Auto SSH Script

Install expect first by:

sudo apt-get install expect

Save script in file:

#!/usr/bin/expect -f
#!/bin/bash

set HOST 192.168.1.109
set USER root
set PASS toor

spawn ssh $USER@$HOST
match_max 100000
expect "password:"
send $PASS
send "\n"
interact

Run script by giving permission and ./script_name.sh.
N.B. bash script_name.sh or sh script_name.sh will not work because #!/usr/bin/expect will be ignored it's not a bash script, it's an expect script.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License