November 23, 2011

Automatic Login using expect tool and ssh

Automatic Login using expect tool and ssh

In order to save time it is possible to save the login information to a file and then use the expect tool to login to a server.

Before you proceed with this,make sure that expect tool is installed.

else install expect tool

#yum install expect

Now save the login information to a file. Take a look at the below example.

vi server1

#!/usr/bin/expect -f
spawn ssh root@192.168.0.254
expect "password:"
send "password\r"
expect "#"
interact

save the file and exit. Make sure you replace the password in send "password\r" with the real password leaving \r alone. Else you will have to press enter to login to the server

Now use the command to login to the server 192.168.0.254

expect server1

Thats it you have logged in. No password nothing.

No comments:

Post a Comment