« A Few More Days In Paradise | LaTeX2PDF - A Web Utility To Convert LaTeX Into PDF »


Expect - Remote SSH Login

2008.09.12 @ 17:03:04 -0400 under

Expect, Linux, Scripts

Disclaimer

The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor its author is responsible for any/all damage - intellectual or otherwise.


What Is Expect?

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
divider


Your Thoughts



Opinions expressed in these pages are purely personal and do not reflect those of any other institution and/or individual
© 2002-2018 Gowtham • All Rights Reserved