Search code examples
sshterminalssh-tunnelsshpass

When trying to use sshpass command with alias, getting Permission denied response


When I am trying to make a normal sshpass command in my terminal it is working correctly. This is the command I am using:

sshpass -p 'Rito$pass@20' ssh '[email protected]'

When I am trying to use the same command by creating an alias, it is responding Permission denied, please try again.

I have created my alias in .profile file. This is how my alias looks:

alias myalias="sshpass -p 'Rito$pass@20' ssh [email protected]"

Can anyone please explain why I am getting Permission denied error when I am trying to use the alias, and how to resolve it?

=================================================================

Update:

Based on @pynexj comment I ran the command set -x; myalias; set +x and found that the characters post $ are not getting considered in the password. My password was Rito$pass@20 but it was considering only Rito@20, that is all the characters after including the $ is ignored till the @ character.


Solution

  • According to the comment, there's a $ char in the password. So to fix you need to escape the $ char.

    For example if the password is pa$$word:

    alias myalias="sshpass -p 'pa\$\$word' ssh [email protected]"