Dobenquell
Dobenquell

Reputation: 1

sshpass, permission denied, please try again

I know that this question has been proposed several times (https://superuser.com/questions/606252/how-to-use-sshpass-for-chained-connection and https://unix.stackexchange.com/questions/320412/how-to-use-sshpass-to-supply-a-password-on-the-second-ssh-hop) but all the solutions that I've found until know are not working. I'm tryng to access a third machine (third@machine) by using sshpass in order to not be prompted to insert a password. However,it is mandatory to use a bridge machine (bridge@machine) before entering the final one. Each time I need to enter the passwords for the bridge@machine and for the third@machine, so my workflow is:

ssh bridge@machine

insert password:

ssh third@machine

insert password

Until now, I was able to avoid the first password by using sshpass in the proxycommand inside the ~.ssh/config file as follow:

vi ~.ssh/config :

Host *.reference
User example_user
ProxyCommand sshpass -p $bridge_machine_password$ ssh -o StrictHostKeyChecking=no bridge@machine "nc -w 60 `basename %h .reference` %p"

and contemporary I've define an alias named "curie" in the .bashrc file which is:

alias curie='ssh [email protected]'

So if run the alias curie I'm able to avoid the first password but I'm still prompted for the password of the third@machine.

For this reason I've tried to use sshpass to access the third@machine in the following manner:

>sshpass -p 'third_machine_password' ssh -oProxyCommand="ssh -W %h:%p bridge@machine" third@machine

Unfortunately, this gives back :

Permission denied, please try again.

Could be a restriction imposed by the third@machine or I'm doing something wrong?

Upvotes: -1

Views: 4008

Answers (2)

syed adeeb
syed adeeb

Reputation: 139

if your password contains special characters such as $... eg abcd@1234$$ then use \ with the special character....add this \ before each $$....it worked for me

Upvotes: 2

Dobenquell
Dobenquell

Reputation: 1

Find a solution:

created firstly in the config file the proxy command

Host *.reference
  User bridge
  ProxyCommand sshpass -p passwd_bridge_machine2 ssh -o StrictHostKeyChecking=no bridge@machine2 "nc -w 60 `basename %h .ciment` %p"

after this command set in the config I created the alias in the .bashrc file:

alias curie='sshpass -p passw_third@machine3 ssh [email protected]'

It is important to add the .reference line because it will firstly call the proxycommand in the config file and then use the sshpass in the alias. Once everything is settled it is only necessary to run the alias in the terminal to open the third machine withou any password.

Hope it helped someone else

Upvotes: 0

Related Questions