[英]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
:我现在被迫输入
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.查看sshfs wiki,它似乎用于挂载远程文件系统。
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.这看起来更像是一个 SSH 问题,如果您的 ssh 配置配置为仅使用密码,那么您将收到提示。 Its better (and more secure) to use a SSH key without a passphrase imo.
使用没有密码短语 imo 的 SSH 密钥更好(也更安全)。
As per the wiki:根据维基:
SSH will ask for the password, if needed.
如果需要,SSH 将要求输入密码。 If you do not want to type in the password multiple times a day, see SSH keys .
如果您不想一天多次输入密码,请参阅SSH 密钥。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.