I would like to create an array with the variables $user
and $host
in order to pass them to the ssh
command.
I have tried:
my_array=('something1' 'something2' 'user' 'host_ip')
sudo ssh ${my_array[2]}@${my_array[3]}
my_array=('something1' 'something2' 'user' 'host_ip')
sudo ssh host -l ${my_array[2]} ## here host is not a variable
my_array=('something1' 'something2' 'username' 'host_ip')
my_var="${my_array[2]}@${my_array[3]}"
sudo ssh $my_var
In all cases I get to be asked from the local user password (because of sudo
) and my answer is accepted. When I type the remote user password, I get the following output and I get to try agian:
Permission denied, please try again.
Notes:
- I am using an IP as the host
- My password is the right one and it is working when I do not use variables (
sudo ssh user@host
). - I recently installed the sshpass package
Thank you very much!
Edit
For some reason the following day all the above and the solutions bellow worked... Can someone explain this?