I have a script with ssh commands that are using a jump host:
scp -J user@jump file admin@server
ssh -J user@jump admin@server "touch hello"
I would like to ask for the passwords only once and tried sshpass
:
sshpass -p "PasswordForJump" scp -J user@jump file admin@server
This will only ask the password for admin@server. However, since there are two ssh/scp commands, I still have to enter the admin password twice.
I tried to nest the sshpass
but the script is blocked:
sshpass -p "PasswordForJump" sshpass -p "PasswordForServer" ssh -J user@jump admin@server
Naively I have tried to set the two passwords in a file (one per line) by expecting sshpass
to use one after the other but this fail too.
Can I use sshpass
to supply two passwords ?
I got it to work with the proxy command:
The above example is from my answer to a similar question in StackExchange: https://unix.stackexchange.com/questions/597351/sshpass-with-ssh-j-jump-host/668489#668489
This example is more secure that using the
sshpass -p
option to pass in the password. Using the-p
argument allows the password to be seen in the system process list. Using a combination of-e
and-d
will avoid that from occurring.