Auto start SSH connection - SOLVED

Questions about Wi-Fi and other network devices, file sharing, firewalls, connection sharing etc
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Guifan

Auto start SSH connection - SOLVED

Post 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?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: Auto start SSH connection

Post 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.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Guifan

Re: Auto start SSH connection

Post 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.
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: Auto start SSH connection

Post 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.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Guifan

Re: Auto start SSH connection

Post 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.
Locked

Return to “Networking”