Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Forked from enoch85/lussh
Created October 20, 2020 19:46
Show Gist options
  • Select an option

  • Save gadelkareem/c69bd844f8bb49d8b9ccac367d80b6b3 to your computer and use it in GitHub Desktop.

Select an option

Save gadelkareem/c69bd844f8bb49d8b9ccac367d80b6b3 to your computer and use it in GitHub Desktop.

Revisions

  1. Daniel Hansson revised this gist Jan 31, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lussh
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ if [ -n "$host" ]; then
    if [ -f ~/.ssh/id_rsa.pub ]; then
    echo "RSA public key OK."
    else
    ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
    ssh-keygen -b 4096 -f ~/.ssh/id_rsa -N ""
    fi

    echo "Appending your RSA public key to the server's authorized_keys"
  2. @sbleon sbleon created this gist Feb 19, 2013.
    64 changes: 64 additions & 0 deletions lussh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    #!/bin/bash

    # make sure to run this with /bin/bash, NOT /bin/sh

    echo
    echo This script will help you setup ssh public key authentication.



    host=dummy
    port=22

    while [ -n "$host" ]; do
    echo -n "SSH server: "
    read host
    if [ -n "$host" ]; then
    echo -n "user[$USER]: "
    read usr

    #If user not provided use current user
    if [ -z "$usr" ]; then
    usr=$USER
    fi

    echo -n "port[$port] "
    read port
    if [ -z "$port" ]; then
    port=22
    fi

    echo "Setting up RSA authentication for ${usr}@${host} (port $port)..."
    if [ -f ~/.ssh/id_rsa.pub ]; then
    echo "RSA public key OK."
    else
    ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
    fi

    echo "Appending your RSA public key to the server's authorized_keys"
    scp -P $port ~/.ssh/id_rsa.pub ${usr}@${host}:~/

    # Append public key to authorized keys and fix common
    # permission problems, eg. a group-writable .ssh dir,
    # or authorized_keys being readable by others.
    ssh ${usr}@${host} -p $port "if [ ! -d ~/.ssh ]; then
    mkdir ~/.ssh
    fi
    chmod 700 ~/.ssh
    cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
    chmod 0600 ~/.ssh/authorized_keys
    rm ~/id_rsa.pub"
    echo
    echo "You should see the following message without being prompted for anything now..."
    echo
    ssh ${usr}@${host} -p $port "echo !!! Congratulations, you are now logged in as ${usr}@${host} !!!"
    echo
    echo "If you were prompted, public key authentication could not be configured..."

    echo
    echo "Enter a blank servername when done."
    echo
    fi
    done

    echo "End of configuration."