[英]How to ssh+expect to login and su to another user on remote machine?
I'm from local machine, ssh to remote machine, and sudo su to admin user. 我是从本地计算机,ssh到远程计算机,而sudo su是管理员用户。 I don't wish to quit from ssh, I wish to stay on remote machine, so I tried:
我不想退出ssh,希望留在远程计算机上,所以我尝试了:
$cat
#!/usr/bin/expect
spawn "/usr/bin/ssh myself@myremotebox -t \"/usr/bin/sudo su admin\""
expect "Password: " {send "mypassword\r"}
$./myssh.exp
spawn /usr/bin/ssh myself@myremotebox -t "/usr/bin/sudo su admin"
couldn't execute "/usr/bin/ssh myself@myremotebox -t "/usr/bin/sudo su admin"": no such file or directory
while executing
"spawn "/usr/bin/ssh myself@myremotebox -t \"/usr/bin/sudo su admin\"""
(file "./myssh.exp" line 2)
Seems I 've got syntax error. 似乎我有语法错误。 I tried to add/remove the "\\" inside and outisde my spawn statement, neither works.
我试图在内部添加/删除“ \\”并且超出我的spawn语句,但均无效。 How to fix it?
如何解决?
Thanks! 谢谢!
Should be: 应该:
spawn /usr/bin/ssh -t myself@myremotebox "/usr/bin/sudo su admin"
expect "Password: " { send "mypassword\r" }
interact
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.