09
September

SSH Automatic Password Entry

I always thought that to use ssh in a shell script you had to authenticate with keys(no always possible) but I’ve just discovered a really useful way of passing the password directly to the ssh client though a shell script. This could have saved me so much faffing about in the past if only I’d found it sooner. Anyways here it is:


#!/bin/sh

PASSWORD=”{password}”

expect -c “set timeout -1;\
spawn ssh {servername} -l {username} \”{command}\”;\
match_max 100000;\
expect *password:*;\
send — $PASSWORD\r;\
interact;” | tail -n+3

PS this is really not all that secure so I’d only use as a last resort (so be warned).