Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 shell 脚本,我需要从服务器 A 执行该脚本,该脚本也在服务器 B 中执行命令。但我只能以服务器 B 中的 root 用户身份执行这些命令。
如果我手动登录到服务器 B,那么我必须将用户更改为 root 并执行删除命令。为了自动执行此操作,我尝试编写脚本并从服务器 A 执行,但它要求我输入密码。如何在脚本中添加我的密码?(虽然不推荐),或者请建议是否有其他方法来解决这个问题。
您可以使用带有 -p 选项的 sshpass 命令
sshpass -p 'your_password' ssh root@your_host ls
有关更多选项,请参阅sshpass手册
使用 nopasswd 在 /etc/sudoers 中添加您的用户名以删除密码提示
$ visudo user ALL=(ALL) NOPASSWD: ALL