Page 1 of 1

Auto start SSH connection - SOLVED

Posted: Thu Mar 01, 2018 9:47 am
by Guifan
After setting up an SSH connection between my laptop as host and desktop as client (both running LM 18.3) the host IP address is listed in the client file system under Network. I created links to folders by dragging them to the Bookmark area in the left hand pane. In order to automate the connection on startup I created the following script:

#!/bin/bash
ssh <myname>@192.168.1.4

saved it as Serverconnect, made it executable by running chmod +x Serverconnect and added it as a Custom command in Startup Applications. On restarting the client the server IP address is not listed in the file system and the folder bookmark folder icons now have what looks like a miniature browser icon imposed upon them. However, as soon as I click on any one of these Bookmarked folders the folder opens, the browser mini-icons disappear and the server IP address appears under Network.

To complete the connection without this manual intervention (so I can add further commands) I think I need to add a mount command to Serverconnect but nothing I have tried so far works. Please can anyone tell me how to get my automated server connection fully mounted on startup?

Re: Auto start SSH connection

Posted: Thu Mar 01, 2018 2:24 pm
by altair4
I'm confused a bit by your post.

You talk about it showing up under Network in your file manager but your script connects to it via the shell.

If you want it to show up under Network at login time your command would be:

Code: Select all

gvfs-mount sftp://<myname>@192.168.1.4
And it would be just that line in Startup Applications - there is no need for a script file.

Re: Auto start SSH connection

Posted: Fri Mar 02, 2018 9:02 am
by Guifan
Thank you for your reply. I have tried your suggestion and get exactly the same result as with my script. It seems that a further step is required to complete the connection.

Re: Auto start SSH connection

Posted: Fri Mar 02, 2018 9:16 am
by altair4
Your script will not allow you to access the server via the file manager because you are connecting to the server via the shell. You are in a live connection to the server and there is no mount point so there is nothing for the file manager to access. A gvfs-mount will create a mount point.

If the problem is this: On restarting the client the server IP address is not listed in the file system then perhaps you didn't select "Remember Forever" when you passed credentials the first time through the file manager.

If you didn't do that or if you don't want to do that then create a file in your home directory - for example at /home/tester/.ssh/sshpasswd - containing one line - the password to the server.

Then change the line in startup applications to this:

Code: Select all

gvfs-mount sftp://<myname>@192.168.1.4 < /home/tester/.ssh/sshpasswd
EDIT: There is no need to restart the client machine - as in a reboot. All you need to do is logoff and log on again. Startup Applications happen at login time not boot time.

Of course you can also use gigolo to do all this - it's a graphical front end to gvfs-mount.

Re: Auto start SSH connection

Posted: Sat Mar 03, 2018 1:32 pm
by Guifan
Thanks, Altair, I used SSH key based authentication to avoid any issues with passwords. I found that once a connection was established, it was preserved when logging out and in again but lost when re-starting. However I have found a fix based upon:
https://www.tecmint.com/sshfs-mount-rem ... using-ssh/
I installed SSHFS, created a new directory (sudo mkdir /mnt/server), created a new group 'fuse' to which I added my username and then edited /etc/fstab to add the following line:
sshfs#<myname>@192.168.1.4:/home/<myname>/DATA/ /mnt/server fuse.sshfs IdentityFile=~/.ssh/id_rsa defaults 0 0
On testing I found that gvfs-mount sftp://<myname>@192.168.1.4 was still required as a Startup command.
With these changes the server files are always accessible on the client machine without the need for any manual actions, even if both machines are turned completely off and on again. I don't understand how this works but I hope it will be a stable solution.