Results 1 to 6 of 6

Thread: Mount sshfs using script woes

  1. #1
    Join Date
    Feb 2010
    Location
    U.K.
    Beans
    782
    Distro
    Ubuntu 12.04 Precise Pangolin

    Mount sshfs using script woes

    Hi,

    No doubt I have missed something obvious here but I can't see what

    Just trying to remove the need to type a mount command by having it in a script on my desktop.

    Client: Ubuntu 12.04 Desktop 64bit
    Server: Ubuntu 10.04 Server 64bit

    On the client I have created a directory ~/ubuserver_shared

    This command:
    Code:
    sshfs -o idmap=user $USER@ubuserver:/home/crypto/shared ~/ubuserver_shared
    works fine from the command line. The remote directory gets mounted as expected.

    So I created a simple script:
    Code:
    #!/bin/bash
    sshfs -o idmap=user $USER@ubuserver:/home/crypto/shared ~/ubuserver_shared
    Again this works fine from the command line.

    However, when executed from the desktop using "Run in Terminal" the terminal window opens and prompts for the password (as expected) - enter the password and Terminal disappears and a GUI OpenSSH popup prompt appears asking for the password again - enter the password again and that popup disappears but nothing is mounted to ~/ubuserver_shared.

    What am I doing wrong here? It seems like the OpenSSH GUI is unnecessarily intervening somehow.

    Thanks
    crypto

  2. #2

    Re: Mount sshfs using script woes

    Make a new launcher with this command property

    Code:
    gnome-terminal -e "/path/to/your.sh"
    your.sh includes:
    Code:
    #!/bin/bash
    sshfs -o idmap=user $USER@ubuserver:/home/crypto/shared ~/ubuserver_shared
    HTH.
    Others may have a more elegant solution.
    Windows assumes the user is an idiot.
    Linux demands proof.

  3. #3
    Join Date
    May 2010
    Location
    uk
    Beans
    9,249
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Mount sshfs using script woes

    Hi

    What is the value of $USER when run from the script requiring elevated privileges ?

    Is it the user you are expecting ?

    Use full paths as well (including sshfs).

    Kind regards
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  4. #4
    Join Date
    Feb 2010
    Location
    U.K.
    Beans
    782
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Mount sshfs using script woes

    OK - still banging my head on this one, but have made minor progress.

    As for creating a launcher - that seems nigh on if not actually impossible in 12.04

    @matt_symes
    The user is being returned correctly and the usernames and UIDs match between systems. The password being prompted for is the SSH password for the server not a sudo / elevation password. I've added full paths in as suggested - but still the same result. However, I added:
    Code:
    read -p "Press any key to continue... " -n1 -s
    as the last line of the script so it pauses before finishing. And I find that until I press the any key the remote directory is actually mounted and functions fine. As soon as I hit a key, the script finishes and the Terminal window exits - and the remote dir is no longer mounted.

    When run from command line I end up with two processes running:
    Code:
     4705 ?        S      0:00 ssh -x -a -oClearAllForwardings=yes -2 crypto@ubuserver -s sftp
     4707 ?        Ssl    0:00 /usr/bin/sshfs -o idmap=user crypto@ubuserver:/home/crypto/shared /home/crypto/ubuserver_shared
    When run from the desktop or Nautilus I end up with four processes until a key is pressed to complete the script:
    Code:
    4912 pts/2    Ss+    0:00 /bin/sh -c '/home/crypto/mount_ubuserver_shared.sh'
     4914 pts/2    S+     0:00 /bin/bash /home/crypto/mount_ubuserver_shared.sh
     4921 pts/2    S+     0:00 ssh -x -a -oClearAllForwardings=yes -2 crypto@ubuserver -s sftp
     4925 ?        Ssl    0:00 /usr/bin/sshfs -o idmap=user crypto@ubuserver:/home/crypto/shared /home/crypto/ubuserver_shared
    So it seems the ssh process belongs to the pts/X - so when the Terminal exits it takes the ssh process out with it killing the mount. I'm thinking I need to change my script to background the command - time for some more meddling

  5. #5
    Join Date
    Mar 2007
    Location
    Denver, CO
    Beans
    7,958
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Mount sshfs using script woes

    I found a page that might help you:

    http://askubuntu.com/questions/5363/...e-command-line

    Your problem is definitely one of one the terminal closes, your running processes within the terminal are closed as well. You need to keep the terminal open if you want the running processes to remain (remember running processes within a terminal are local to the terminal -- not global to the OS -- this means when the terminal is killed, everything running inside the terminal is killed as well).

  6. #6
    Join Date
    Feb 2010
    Location
    U.K.
    Beans
    782
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Mount sshfs using script woes

    Thanks kevdog

    I have given up with that approach now (tried backgrounding the command in the script - but of course that means I don't see the password prompt!) and added it to the fstab instead.

    Useful refs:
    SSH Mount In fstab: http://ubuntuforums.org/showthread.php?t=1173714
    Make umount work with sshfs: http://www.unicom.com/blog/entry/651

    Now it is mountable / umountable from both Nautilus and command line - good enough for me
    Last edited by cryptotheslow; March 3rd, 2012 at 03:00 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •