How can I set up nautilus to use a ssh connection established by an expect script?

2

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!

Daniel Förster

Posted 2016-03-03T16:25:03.983

Reputation: 38

Answers

1

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

Jakuje

Posted 2016-03-03T16:25:03.983

Reputation: 7 981

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. – Daniel Förster – 2016-03-03T16:53:40.403

Yes. I forgot thy syntax again. But the though was that you don't have to write the expect script, but you might use sshpass 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. – Jakuje – 2016-03-03T16:57:20.117

Ok, thanks, I guess this would work. I realize now however that port forwarding is prohibited by the jumpbox. – Daniel Förster – 2016-03-03T17:03:13.467

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. – Jakuje – 2016-03-03T17:11:31.180

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. – Daniel Förster – 2016-03-03T17:32:53.823

Yes. Of course. My bad. There was also typo in the LocalForward option. Can you give it one more try? – Jakuje – 2016-03-03T17:36:24.633

This works now, but I don't see a big difference between ssh remote and ssh remote-forwarded. Both work just fine, is it a question of entering the password? Another point is that I did not succeed with SSHPASS=password sshpass -e ssh remote and used ssh remote instead. Anyway as I said, entering a password doesn't bother me in command line and nautilus can save the password. Maybe for others having the same problem: Don't forget to specify your user names on the different machines, for example via a "User username" entry in .ssh/config. Thank you so much! – Daniel Förster – 2016-03-03T18:19:23.767

Especially thank you for a solution without an expect script. I didn't like this idea anyway. – Daniel Förster – 2016-03-03T18:28:26.173

Yes, exactly as you write. The remote-forwarded should not need the password for proxy. Please, also don't forget to mark this answer as a solution, if it solved your problem. – Jakuje – 2016-03-04T00:29:28.520