---
title: "Keyless Auto Login SSH Script"
description: "keys less login has been easy always with ssh keygen and copy-id, but just a small bash loop will help auto login on in JS."
url: "https://h3manth.com/scribe/keyless-auto-login-ssh-script/"
canonical_url: "https://h3manth.com/scribe/keyless-auto-login-ssh-script/"
markdown_url: "https://h3manth.com/scribe/blog/keyless-auto-login-ssh-script.md"
publishDate: "2011-04-09T00:00:00.000Z"
author: "Hemanth HM"
category: "linux"
tags: ["bash","linux"]
word_count: 182
reading_time_minutes: 1
x_markdown_tokens: 419
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# 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 in JS.

**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
    }
    EOF
    
    # exec new shell or even source the rc?
    bash
    

**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! ](https://github.com/hemanth/futhark/raw/master/ssh-auto.bash)Execute it and just type **assh** (hit enter) and stay connected forever ;)
