ssh - 如何隐藏 ssh 期望用户/密码

我的 Expect 脚本以明文形式显示密码/用户,我想隐藏它。

#!/usr/local/bin/expect
###########################################################################################    ############
# Input: It will handle two arguments -> a device and a show command.
###########################################################################################    ############
# ######### Start of Script ######################
# #### Set up Timeouts - Debugging Variables
log_user 0
set timeout 10
set userid  "USER"
set password  "PASS"
# ############## Get two arguments - (1) Device (2) Command to be executed
set device  [lindex $argv 0] 
set command [lindex $argv 1]
spawn /usr/local/bin/ssh -l $userid $device
match_max [expr 32 * 1024]
expect {
    -re "RSA key fingerprint" {send "yes\r"}
    timeout {puts "Host is known"}
}
expect {
    -re "username: " {send "$userid\r"} 
    -re "(P|p)assword: " {send "$password\r"}
     -re "Warning:" {send "$password\r"}
    -re "Connection refused" {puts "Host error -> $expect_out(buffer)";exit}
    -re "Connection closed"  {puts "Host error -> $expect_out(buffer)";exit}
   -re "no address.*" {puts "Host error -> $expect_out(buffer)";exit}
    timeout {puts "Timeout error. Is device down or unreachable?? ssh_expect";exit}
}
expect {
   -re "\[#>]$" {send "term len 0\r"}
   timeout {puts "Error reading prompt -> $expect_out(buffer)";exit}
}
expect {
   -re "\[#>]$" {send "$command\r"}
   timeout {puts "Error reading prompt -> $expect_out(buffer)";exit}
}
expect -re "\[#>]$"
set output $expect_out(buffer)
send "exit\r"
puts "$output\r\n"

最佳答案

...并添加 -OUseBatchMode=Yes这样,如果您的 key 有问题,ssh 将立即失败(您可以验证退出代码),而不仅仅是退回到密码模式并挂起(因为您正在交互运行)

https://stackoverflow.com/questions/2991633/

相关文章:

grails - 如何在 Grails 中对存储过程记录进行建模?

svn - KDESvn 'Add ssh-identities to ssh-agent' 不起作

grails - 从过滤器访问 'session'

c# - 具有永久ShellExec连接的SharpSSH

bash - 通过ssh登录时自动运行脚本

git - Git推送错误:ssh:无法解析主机名domain.com [:7555]:提供了节点名

spring - 尝试连接到MongoLab时URL格式的MongoException

grails - Grails 3数据库迁移问题

php - 从php运行shell脚本

ubuntu - ssh 不会在 ubuntu 10.04 64bit 中自动启动