gpt4 book ai didi

linux - 如何在 bash 脚本命令中提供 2 个输入?

转载 作者:太空宇宙 更新时间:2023-11-04 12:16:53 24 4
gpt4 key购买 nike

我正在尝试使用 sshfs 将远程文件夹挂载到我的计算机上。我的 bash 脚本如下:

sudo sshfs -o allow_other id@afs1.domain.com:/ /home/kr1shna/remote -o password_stdin <<<"xxxxxx"

每次我执行此命令时,它都会提示我输入 root 密码。

所以我尝试了:

echo "rootpassword" | sudo -S sshfs -o allow_other id@afs1.domain.com:/ /home/kr1shna/remote -o password_stdin <<<"xxxxxx"

我知道重复我的 root 密码不是一个好习惯,但我是唯一一个使用这台计算机的人。

我可以通过什么方式在 bash 脚本中提供 root 密码和其他密码参数?

谢谢。

最佳答案

尝试定义要传递给命令的值。

例如

password="$(echo 'HelloWorld!')";
echo "Your password is $password";

在您的情况下,它将是:

password="$(echo 'xxxxx')"
sudo sshfs -o allow_other id@afs1.domain.com:/ /home/kr1shna/remote -p $password

而且我知道您可能对我们都告诉您不要这样做感到恼火,但这确实会给您的服务器带来潜在的安全漏洞。我强烈建议不要这样做。

关于linux - 如何在 bash 脚本命令中提供 2 个输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47191189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com