Expect – Remote SSH Login

Expect is a UNIX automation and testing tool, written by Don Libes as an extension to the Tcl scripting language, for interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. It uses UNIX pseudo terminals to wrap up sub-processes transparently, allowing the automation of arbitrary applications that are accessed over a terminal. With Tk, interactive applications can be wrapped in X11 GUIs. Expect has regular expression pattern matching and general program capabilities, allowing simple scripts to intelligently control programs such as telnet, ftp, and ssh, all of which lack a programming language, macros, or any other program mechanism. The result is that Expect scripts provide old tools with significant new power and flexibility.

The Script

When a server keeps prompting for password at SSH attempts in spite of setting up RSA/DSA keys, this script can be used to overcome that issue. Make sure that the script has 700 permission as it will contain your password in plain text.

#! /usr/bin/expect
 
# Fri, 12 Sep 2008 12:58:10 -0400
 
# Edit the following line - $USER@$SERVER
spawn ssh your-useid@your-server-name
 
# First time connection will print out some text for
# which one needs to type 'yes' to continue
# Comment these two lines after the first attempt
expect "*Are you sure you want to continue connecting*"
send   "yes\r"
 
# Put the password here
expect "*assword*"
send   "YOUR-PASSWORD\r"
 
# Start interacting
interact

2 Replies to “Expect – Remote SSH Login”

  1. Can anyone recommend the best Remote Management & Monitoring software for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central it support
    ? What is your best take in cost vs performance among those three? I need a good advice please… Thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.