Keyless auto login SSH script

keys less login has been easy always with ssh keygen and copy-id, but just a small bash loop will help auto login on disconnections. Key-less auto login SSH simple script, but helped me to make one of my team mates switch to GNU/Linux.

Simple script :

# Read the hostname and username for SSH login.
read -p "Enter your hostname/ip :" host_name
read -p "Enter your login name  :" login_name

# Generate RSA key.
echo Generating RSA keys
ssh-keygen -t rsa

# Copy the generated key.
echo Copying keys to ${host_name}
ssh-copy-id -i ~/.ssh/id_rsa ${login_name}@${host_name}

# Add a function to ~/.bashrc.
cat >> ~/.bashrc << EOF
function assh(){
while true; do ssh ${login_name}@${host_name} ; done

# exec new shell or even source the rc?

Just do this when you execute the script :

Enter file in which to save the key (/home/hemanth/.ssh/id_rsa): [Hit enter]
Enter passphrase (empty for no passphrase):[Hit enter]
Enter same passphrase again: [Hit enter] 
Your identification has been saved in /home/hemanth/.ssh/id_rsa.

GET it! Execute it and just type assh (hit enter) and stay connected forever ;)

Share this