Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set up SSH with Public Key authentication on Ubuntu?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 677
    Comment on it

    How to Setup SSH with Public Key Authentication on Ubuntu 14.04

    This blog will let you know how to set up an SSH server with public-key authorization  SSH is a great tool to control Linux-based computers remotely.

    Installing SSH On The Server

    First Step:

    First of all we need to install the SSH on our server. To achieve this write the following command: (Note: Login with root)

    apt-get install ssh

    Preparations On Our Client (Desktop) System

    Second Step:

    Desktop machine need to be prepare to connect the server. So, the SSH-server has been installed on a different machine.  We will install ssh client to your desktop machine. Then install the client:

    apt-get install openssh-client

    Switch back to your normal user (not root, respectively). Then type these commands in order:

    mkdir ~/.ssh
    chmod 700 ~/.ssh
    cd ~/.ssh

    Private-key and public-key pairs need to be generated first. Public-key will be uploaded to the server and private-key will be used to log in to the server. When it will ask to enter passphrase then enter it for security purpose so don't forget your passphrase.

    ssh-keygen -t rsa -C "A comment..."

    Then we copy the public key (which we've generated just before) to our (remote) server. The remoteuser should not be root! Choose the default non-root user as remoteuser. (Note the colon at the end of the line! It's important.)

    scp -p id_rsa.pub remoteuser@remotehost:

    Then we log in with SSH, and we copy the public key to its right place:

    ssh remoteuser@remotehost
    mkdir ~/.ssh
    chmod 700 ~/.ssh
    cat id_rsa.pub >> ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
    mv id_rsa.pub ~/.ssh
    logout

    SSH client will not allow to login to the server so we need to delete the public key on the desktop. Type this command to do so:

    rm id_rsa.pub

    And then we log back:

    ssh remoteuser@remotehost

    Disabling Password Authentication

    cd /etc/ssh
    cp sshd_config sshd_config.orig
    nano sshd_config

    Now change these lines from the nano text-editor on the screen, open it with the main SSH configuration file.

    PermitRootLogin		yes
    PasswordAuthentication	yes
    UsePAM			yes
    

    To these:

    PermitRootLogin		no
    PasswordAuthentication	no
    UsePAM			no
    

    Then save the file with Ctrl + O , and restart the SSH server:

    /etc/init.d/ssh restart

    Note: You will not be able to login if you disable the password authentication!

    Thanks for reading the blog.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: