PDA

View Full Version : Automating sshfs command



thheggel
February 23rd, 2006, 02:28 PM
I've been trying write an automation script for sshfs using expect and also pexpect. I can't seem to get it right. Does anybody know how to get the sshfs automation working?

This is what i want to do:
Given a username and a password, i want the script to mount the home directory for the username given, at a location on the local machine.

ex: sshfs me@192.168.0.10: /home/thisuser/mountpoint

I don't want a solution using certificates, and automaticly logon to ssh. I wan't to get this working using only scripting.

Anyone?

gmclachl
September 9th, 2006, 01:21 AM
Sorry about bringing this post back from the dead so to speak, but I was having the same problem myself.

Anyway once I downloaded pexpect I wrote a quick and dirty python script to connect.



#!/usr/bin/python
import pexpect
import time

command = "sshfs username@server:/path/to/home/folder /mount/point/"

def start_sshfs():
try:
sshfs = pexpect.spawn(command)
sshfs.expect("Password: ")
time.sleep (0.1)
sshfs.sendline ("YourPassword")
time.sleep (10)
sshfs.expect (pexpect.EOF)

except Exception, e:
print str(e)

def main ():
start_sshfs()

if __name__ == '__main__':
main ()



Hope this helps someone.

Of course this has some security issues as you are storing a password in plain text. So remember to guard against that.
George

HakanS
September 21st, 2006, 05:55 PM
How do I use this script?

fde
September 2nd, 2007, 07:37 PM
up!

cwaldbieser
September 2nd, 2007, 07:49 PM
How do I use this script?

You have to change the line starting with "command =" to have the correct command to mount the sshfs filesystem (e.g. replace the username, server, path to remote folder, and local mount point). You also need to replace "YourPassword" with the actual password used to log on. This is why the original poster cautions that you would have to have your password in plain-text in the script.

artheus
February 24th, 2010, 05:17 PM
I've made an update of this script.. So it will work in Karmic. And with the newest update of sshfs.


#!/usr/bin/python
import pexpect
import time

username = "username"
password = "password"
host = "adress.for.the.host"
hostdirectory = "/path/on/host"
mountpoint = "/path/to/mountpoint"

command = "sshfs " + username + "@" + host + ":" + hostdirectory + " " + mountpoint

def start_sshfs():
try:
sshfs = pexpect.spawn(command)
sshfs.expect(username + "@" + host + "'s password: ")
time.sleep (0.1)
sshfs.sendline (password)
time.sleep (10)
sshfs.expect (pexpect.EOF)

except Exception, e:
print str(e)

def main ():
start_sshfs()

if __name__ == '__main__':
main ()

Hope that this will soon be a native feature of the Ubuntu distro. Just a little checkbox when you mount a network/ssh path. "Automount this on startup"

Cheers,
Artheus

coelho
November 20th, 2010, 03:02 PM
Great solution from http://darklaunch.com/2009/06/05/how-to-remote-mount-with-password-using-sshfs-and-stdin-ubuntu-sshfs-remote-mounting-mosso


echo mypassword | sshfs myuser@ftp.mysite.com:/ ~/mounts/mysite -o workaround=rename -o password_stdin

aaronLund
December 6th, 2011, 07:17 PM
Great solution from http://darklaunch.com/2009/06/05/how-to-remote-mount-with-password-using-sshfs-and-stdin-ubuntu-sshfs-remote-mounting-mosso


echo mypassword | sshfs myuser@ftp.mysite.com:/ ~/mounts/mysite -o workaround=rename -o password_stdin

I'm wondering why this doesn't work when you plug it into "Startup Applications"?

Works just fine in a terminal.