0

I am using commands to connect to remote server using ssh

spawn ssh userId@host
expect "password:"
send "password\r"

Issue is sometime,even before shell prompt for password, send command is run which result's in password getting display in plain text on console.

It there a way to

  1. make sure, send is always called after expect
  2. or if it get's called, it should display something like ******* and not plain text

I read the documentation of send but no luck there.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Ashishkumar Singh
  • 3,580
  • 1
  • 23
  • 41
  • 1
    `sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM` ? http://stackoverflow.com/questions/12202587/automatically-enter-ssh-password-with-script – Ronak Patel Aug 10 '16 at 12:50
  • 1
    If possible, use public-key authentication to login without a password, instead of exposing your password in a script (which both `sshpass` and `expect` do). – chepner Aug 10 '16 at 14:01
  • This is not in any way a `bash` question. `expect` is its own, TCL-based language -- when you're running expect, you're not in bash anymore. – Charles Duffy Aug 10 '16 at 15:49

1 Answers1

1

You can hide output from console ussing stty or log_user.

Using stty

spawn ssh userId@host
expect "password:"
stty -echo
send "password\r"
stty echo

Using log_user

spawn ssh userId@host
expect "password:"
log_user 0
send "password\r"
log_user 1
mihir6692
  • 177
  • 1
  • 4
  • 19