We help IT Professionals succeed at work.

How do you specify a user(root)  password when executing sshfs  in a c shell script?

Medium Priority
455 Views
Last Modified: 2012-05-12
How do you specify a user(root)  password when executing sshfs  in a c shell script?

My sshfs connection in my c shell script looks like this:
sshfs root@205.114.4.224:/root/mtest2 ~/mnt

When I execute my c shell scripts I am prompted for the "root" user password.

Is there a way to pass the password as an argument in the command.

Comment
Watch Question

CERTIFIED EXPERT
Commented:
Just setup the ssh keys and have it password less.
CERTIFIED EXPERT

Commented:
CERTIFIED EXPERT

Commented:
On the client machine, look in ~/.ssh for the file "id_rsa.pub".  If it doesn't exist, please do:

ssh-keygen -t rsa

Hit <enter> at all the prompts until its done.

Then copy ~/.ssh/id_rsa.pub into your clipboard, it will look something like the attached

Log into 205.114.4.224 and edit /root/.ssh/authorized_keys and paste the key at the end of that file.  If the file doesn't exist, create it and just put that single key in there.  Then do "chmod 600 authorized_keys"

The next time you issue your sshfs command, it should bypass the password and use the key for authorization.

There is no way to pass a password as a command-line option directly to sshfs, but if you don't want to use keys, you can use an expect script.  You would need to install the program "expect" and also the tcl libraries to accomplish this.  I think the key route is much easier.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDftjpw3E3i15MgfjX8Sp1dGQp7cQu6hgaOjf/oldEyZ96BA8Ymxa99iyVdHTCHzcQ63UCTg3TegU4fn/GPRTZC6AsE/ZVOytUl3YxaGu10c/fAW4qO6x7BbVgrmj7qHvV7JcnkwyteUG6E3BZaiEvPv4wM46HJJJ1vTpHTRnplQZY7SMs1nxd999RgLFmXUnpmmbIis1swovA7oS8TjUPb3hx+VGE9QcU0TdRY/k3cGsTh1INlUb1IWmd/0NlLsyI3PLU5j5kdTr1FnrzaBATCyXdpaIGc6P6QFvtMPtpuw1eXQb98hCgc2BuNNPlufYuw92g75+I3BJ3TQyRvDnml user@foo.bar.com

Open in new window

CERTIFIED EXPERT

Commented:
It's generally a Very Bad Idea (tm) to allow remote login to the root account.
A utility I've found valuable, as opposed to manually copying the public key from one machine to the other, is "ssh-copy-id":

ssh-copy-id /home/user/.ssh/id_dsa.pub user@205.114.4.224

Open in new window


It'll ask you for the password when running that command, but if all is successful it won't ask again.  I prefer using this utility because using keys with ssh (or sshfs) can be tricky due to very strict permissions needing to be set on the .ssh folder.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.