简体   繁体   中英

Linux - Pass password inside script shell

I have trouble to pass a password automatically in my script. This is how it looks like when I do it manually:

sshfs -o nonempty user@sftp.server.com:/ /home/administrator/data

I am now forced to enter the password for sshfs :

password

I try to automate that in a script and pass the password like this to standard input:

#!/bin/bash

echo "password" | sudo -S sshfs -o nonempty user@sftp.server.com:/ /home/administrator/data

When I run the script, I am still forced to enter the password. What am I doing wrong?

Looking at the sshfs wiki it seems this is used to mount a remote file system.

This looks like more of a SSH issue really, if your ssh config is configured to use a password only then you'll get prompted. Its better (and more secure) to use a SSH key without a passphrase imo.

As per the wiki:

SSH will ask for the password, if needed. If you do not want to type in the password multiple times a day, see SSH keys .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM