how to hide ssh expect user/password

Posted by raindrop18 on Stack Overflow See other posts from Stack Overflow or by raindrop18
Published on 2010-06-07T17:17:07Z Indexed on 2010/06/07 17:22 UTC
Read the original article Hit count: 302

Filed under:
|

my perl cgi script I have the password/user on clear text and want to hide it or the user enter the credential interactively.is that possible? here is my code. please any help!! i am very new for perl.

#!/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"

© Stack Overflow or respective owner

Related posts about ssh

Related posts about expect