Ubuntu – How to auto mount using sshfs


I am using the following command to mount a ssh ubuntu directory to my ubuntu pc.

sshfs user@192.xx.xx.xx.xx:/dir/dir /home/username/mount/xxx

My question is, can I create a script for this in my desktop where I can make a double click and run this script when ever I need to mount the drive without manually typing the command always.

Best Answer

  • You could create a launcher and add it to your launcher bar by drag&dropping the .desktop-file there:

        #!/usr/bin/env xdg-open
        [Desktop Entry]
        Name[en_US]=Connect to xy
        Exec=shfs user@192.xx.xx.xx.xx:/dir/dir /home/username/mount/xxx
        #OR: to mount and than open in nautilus (note the '/dir' where ':dir' used to be)
        #Exec=nautilus sftp://user@192.xx.xx.xx.xx/dir/dir
        Comment[en_US]=Connect to xy via ssh
        Name=Connect to xy
        Comment=Connect to xy via ssh

    Suggestion - even less work:

    If you want even less work (=autoconnect) and a graphical user interface, you might want to check out Gigolo Install gigolo. It has the capability of auto-mounting a bookmark, whenever the bookmarked filesystem is present. You might want to check that out.

    sudo apt-get install gigolo   # or use the install link above

    Run gigolo. There is an option in the preferences that puts it into autostart and another to activate the tray icon. Check both. Then add your bookmark.

    Here is a screenshot:

    enter image description here

    Shell way

    Another solution would be to put the following line in your crontab (edit /etc/crontab with sudo privileges):

    @reboot sshfs user@192.xx.xx.xx.xx:/dir/dir /home/username/mount/xxx

    But since Ubuntu's password manager is not present when the command is run you need to use a password-less private/public key pair to authenticate with the ssh server in question (or a similar method of authentication). This would mount it on every reboot.

    Yet another solution would be to edit your /etc/fstab (providing your Ubuntu-Version provides that option).

  • Related Question