This is a kind of follow-up question to this question: ssh, start a specific shell, and run a command on the remote machine?, except more-specifically regarding ash, and focused on the fact that sourcing a .bashrc file as part of starting the shell in the ssh session doesn't work for me.
I'm on an embedded Linux device which has a busybox version of sh and ash, but there is no bash. We share a common username (root), and a common execution environment.
I'd like to have a few custom aliases and a custom PS1 Prompt String 1 variable, however.
Here is an example normal ssh session. Note that I'm using sshpass to pass my password to ssh, with my password stored in the ~/pw file.
You can see that the default shell is -sh and there are no aliases. The default PS1 prompt string also shows no path.
$ sshpass -f ~/pw ssh [email protected] [root@device]$ echo $0 -sh [root@device]$ alias [root@device]$
The device has no bash, but it does have ash, which apparently is bash-like. So, I want to make that my shell as I ssh in. I also want to copy Ubuntu's default ~/.bashrc file, located in /etc/skel/.bashrc on the Ubuntu machine I'm ssh-ing from, to the device at /tmp/.bashrc so I can source it, and I want my ssh command to do that. I can't copy to ~/.bashrc on the remote device because the home dir is read-only.
I tried the following, but get the following error:
cmd:
sshpass -f ~/pw scp /etc/skel/.bashrc [email protected]:/tmp/.bashrc \
&& sshpass -f ~/pw ssh -t [email protected] '. /tmp/.bashrc'
result:
Connection to 192.168.0.2 closed.
No ssh session was established.
I then tried the following command, with the following result, showing that sourcing did not work, although the ash shell was entered.
$ sshpass -f ~/pw scp /etc/skel/.bashrc [email protected]:/tmp/.bashrc \ && sshpass -f ~/pw ssh -t [email protected] '. /tmp/.bashrc; ash' ~ # echo $0 ash ~ # alias ~ #
I can run . /tmp/.bashrc manually now though, and it works fine. Notice how after sourcing, which works, I have an improved prompt string and new aliases:
~ # . /tmp/.bashrc ash: /tmp/.bashrc: line 16: shopt: not found ash: /tmp/.bashrc: line 24: shopt: not found ash: /tmp/.bashrc: line 111: shopt: not found root@device:~# alias l='ls -CF' alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '"'"'s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'"'"')"' la='ls -A' ll='ls -alF'
You also see the ash errors from line 16, 24, and 111 due to shopt not being found. Even if I comment those out in the .bashrc file I send over, the results as shown above are still the same.
How can I get my above command to work? I'd like it to ssh in, set the shell to something more like bash, and source my /tmp/.bashrc file I scp'ed over.
On a similar embedded device which does have bash installed, this cmd works perfectly, as I document in my repo here:
sshpass -f ~/pw scp /etc/skel/.bashrc [email protected]:/tmp \
&& sshpass -f ~/pw ssh -t [email protected] 'bash --rcfile /tmp/.bashrc'
For bash, using bash --rcfile /tmp/.bashrc at the end of the ssh cmd is what I need. But, for the device withOUT bash, I need help getting this behavior with ash or similar.