Sunday, July 2, 2017

Do you ssh too often and to many different machines?

It's been a long time, since I last wrote a post. And this is going to be a short one.
At my recent job, we have all these test environments (about 3500 of them) that have the same username and password.
I kind of got tired typing the username and password every time I had to login to a machine to test out something.

Well a keyless access would definitely have made things easier, but you can understand why you couldn't have keyless access to 3500 environments, each running the risk of being phoenixed anytime.

I created a small expect script to get around the problem. Expect is a bash utility, that helps provide inputs in an automated way for scripts that expect user inputs. You may need to install it.

On a OsX machine, you can simply do brew install expect
#!/usr/bin/expect
set user ""
set ip [lindex $argv 0]
set password ""
spawn ssh $user@$ip
expect "password"
send "$password\r"
interact

The interact on last line opens an interactive ssh shell.

Now, you can save this with a .exp extension, give an executable permission to it. Setup an alias, so that your newssh command lands to this, and you are all set.
This has made me save a couple of seconds on every login. And now I am wondering why did I wait for so many months before doing this :)

No comments :

Post a Comment