In order to automate a ssh connection, I wrote a script using expect, which works just fine. However, I would like to use this script in the nautilus connect to server function. My idea was to include this expect script somehow into the .ssh/config file since nautilus is able to use the connections detailed there, but I don't know how. Unfortunately, I cannot copy an RSA key to the server. It is a multihop connection, and I cannot write to the first server. This first server only asks for a password and the machine to which I can connect. So, the password is not really the problem, as it could also be supplied by nautilus. Any help is appreciated, thank you!
1 Answer
You can't use password in ssh_config
. But you might use port forwarding (if allowed on the jumpbox):
SSHPASS=password sshpass -e ssh -L 2222:remotehost:22 user@jumpbox
and then
ssh -p 2222 localhost
will bring you directly to the remote host. You can put that into your ssh_config
, such as:
Host remote-forwarded
Hostname localhost
Port 2222
and then connect such as
ssh remote-forwarded
Similar way it will work in nautilus.
Port forwarding prohibited on jumpbox
In this case it will get more complicated. You will need to use proxy command to set up port forwarding directly from the remote host. You config will be longer:
Host remote-forwarded
Hostname localhost
Port 2222
Host jumpbox
Hostname jumpbox-host
Host remote
Hostname remote-host
ProxyCommand ssh -W %h:%p jumpbox
LocalForward 2222 localhost:22
Otherwise it should work the same way, first
SSHPASS=password sshpass -e ssh remote
and then directly to the other host:
ssh remote-forwarded
-
Thank you! Unfortunately I have two problems: sshpass does not have an option -L, so I replaced sshpass by ssh, is that ok? And "ssh -p 2222 localhost" gives me the following error: "ssh: connect to host localhost port 2222: Connection refused" Do I need to open port 2222? I am new to this, sorry for asking. Mar 3, 2016 at 16:53
-
Yes. I forgot thy syntax again. But the though was that you don't have to write the
expect
script, but you might usesshpass
to "take you" to the first server. Edit: Give a try the first command with verbose logging (-vvv
). The port forwarding might not be allowed.– JakujeMar 3, 2016 at 16:57 -
Ok, thanks, I guess this would work. I realize now however that port forwarding is prohibited by the jumpbox. Mar 3, 2016 at 17:03
-
I modified the answer for the case with prohibited port forwarding on jumbox. But I didn't test it so there might be still some glitch. Let me know if it works for you.– JakujeMar 3, 2016 at 17:11
-
Great! I see the files in nautilus. Your .ssh/config entry "Host remote" did the trick when entered in nautilus connect to server dialog. However I think your line "SSHPASS=password sshpass -e ssh jumpbox" should be replaced by "SSHPASS=password sshpass -e ssh remote" (?) And "ssh remote-forwarded" also did not work (Error: "ssh: connect to host localhost port 2222: Connection refused"), but it was not necessary. Mar 3, 2016 at 17:32