当我尝试切换到 时,如何在下面的脚本中自动发送密码su
?
目前我可以通过 ssh 登录主机名,自动输入 usingssh password
但sshpass
在此过程中要求我su password
# sshpass -p 'ssh_password' ssh myuser@$hostname "su -c \"cd /some/path/ && ls -l\""
You are trying to access a restricted zone. Only Authorized Users allowed.
Password:
我已经尝试过类似的方法,但不起作用。
sshpass -p 'ssh_password' ssh myuser@$hostname "su myuser su_password -c \"cd /documents/backups/ && ls\""
下面我展示了我测试过的 3 种方法,只有第 3 种接受su_password
,其他 2 种请求密码,当我输入密码时,回答su: incorrect password
1-) 尝试使用用户名和su_password(失败)
# sshpass -p $ssh_password ssh -t $myuser@$hostname "su $myuser 'MysuPassword123' -c \"cd /some/path/ && ls\""
You are trying to access a restricted zone. Only Authorized Users allowed.
Password:
su: incorrect password
Connection to AAA.BBB.CCC.DDD closed.
2-) 仅尝试使用用户名(失败)
# sshpass -p $ssh_password ssh -t $myuser@$hostname "su $myuser -c \"cd /some/path/ && ls\""
You are trying to access a restricted zone. Only Authorized Users allowed.
Password:
su: incorrect password
Connection to AAA.BBB.CCC.DDD closed.
3-) 仅尝试su
不使用用户名/su_密码(成功)
# sshpass -p $ssh_password ssh -t $myuser@$hostname "su -c \"cd /some/path/ && ls\""
You are trying to access a restricted zone. Only Authorized Users allowed.
Password:
docs file1 file2
Connection to AAA.BBB.CCC.DDD closed.
我怎样才能做到这一点?提前致谢。