bash 期望通过 ssh 提示脚本更改密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18391935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
expect script change password prompted over ssh
提问by dwu
Currently I have a bash script that uses expect in it while doing some things over ssh. It looks like:
目前我有一个 bash 脚本,它在通过 ssh 做一些事情时使用了 expect 。看起来像:
#!/bin/bash
#some bash stuff here
...
/usr/bin/expect -c '
spawn somescript.sh
expect "password:"
send "$PASSWD"
'
...
somescript.sh does commands to a remote server over ssh, but now my login requires a change of password. I've tried
somescript.sh 通过 ssh 向远程服务器执行命令,但现在我的登录需要更改密码。我试过了
/usr/bin/expect -c '
spawn somescript.sh
expect "password:"
send "$PASSWD"
expect "current password"
send "$PASSWD"
expect "new password"
send "$NEWPASSWD"
'
but I get an error saying:
但我收到一条错误消息:
WARNING: Your password has expired.\n Password change required but
no TTY available.
回答by Aleks-Daniel Jakimenko-A.
So, somescript.sh
makes an ssh
connection and then you get an error about TTY not being available.
因此,somescript.sh
建立ssh
连接,然后您会收到有关 TTY 不可用的错误消息。
Try -t
option!
尝试-t
选项!
From ssh man page:
从ssh 手册页:
-t Force pseudo-tty allocation. This can be used to execute arbi-
trary screen-based programs on a remote machine, which can be
very useful, e.g., when implementing menu services. Multiple -t
options force tty allocation, even if ssh has no local tty.
回答by Brad Parks
This can be resolved by directly connecting to the box using ssh
(ie not in a script).
这可以通过使用ssh
(即不在脚本中)直接连接到框来解决。
Do that, and it'll prompt you to change your password. Do so, and the error will go away.
这样做,它会提示您更改密码。这样做,错误就会消失。
回答by syncerror
It looks like you are trying run ssh user@server passwd
but because your password expired you have to change it first. Probably when you run expect as spawn user@server
it will ask you for password change and it will works.
看起来您正在尝试运行,ssh user@server passwd
但因为您的密码已过期,您必须先更改它。可能当您运行 expect 时,spawn user@server
它会要求您更改密码并且它会起作用。