In my first example, I made it easy by turning the bash session into an interactive shell, which sets the expand_aliases
shopt_option. There is also a case-statement at the beginning of .bashrc that disallows sourcing .bashrc in non-interactive shells, which in turn, means your .bash_aliases won't be sourced. Furthermore, even if ssh
will interpret this as a non-interactive session, you may use the -t
option to force a pseudo-terminal allocation for menus and screen-based applications to work.
ssh -t user@localhost '/bin/bash -ic update'
It can be accomplished in non-interactive shells, as well, but apt will still need a pseudo-terminal, though (can be solved by changing the frontend used by apt to a non-interactive choice).
ssh -t user@localhost '/bin/bash --init-file ~/.bash_aliases -O expand_aliases -c update'
Next is the use of -p
passwords in sshpass that does not seem to die off. sshpass
should never be used in this way, ever. I can't see a scenario where this is needed. First, it will end up in your history
, i.e., of course, you don't have it turned off. It may also, in some circumstances, end up in the ps tree. sshpass makes very little to hide the pass in this mode. You should at least use the file option or SSHPASS=
.
editor .ssh/passwd_credentials && chmod 400 $_
passwd_credentials should only contain the password.
And is used by the -f
option.
sshpass -f ~/.ssh/passwd_credentials ssh user@localhost
You may also encapsulate your ssh
command in a script file.
#!/bin/sh
SSHPASS='password' sshpass -e ssh user@localhost
ssh -t user@localhost /bin/bash -ic 'update'
– Jan 14 '21 at 09:21