Snippet : Add Your SSH Public Key To A Distant Server

I think I could cover the ssh login subject in a longer article, for now here is a quick snippet to create and add your public ssh key to your server, so you can login into it without typing your password again (and then disable the password login ability to increase your security) :

  1. Pop-up a Terminal window and generate your ssh key (if needed – don’t erase your existing .id_rsa.pub file if you’re already using it !) :
    ssh-keygen -t rsa -b 4096

    This will generate a 4096 bits RSA key.

    – ssh-keygen will generate a 1024 DSA key ;
    – ssh-keygen -t rsa1 will generate a 1024 RSA key ;
    – ssh-keygen -t rsa will generate a 2048 RSA key.

    The main argument why you could generate a weaker RSA encryption is the power and performance consumption, although it doesn’t really matter for modern machines. Thus this would apply to older servers or when it comes to micro-manage your performances.

  2. In the case you can still login with a login/password couple, type :
    ssh-copy-id username@remote_host

    where, of course, username is the one you want to login with, remote_host is, well, your remote server IP or URL.

  3. That’s it ! Try to login into your server with :
    ssh username@remote_host

    You might be prompted once about the new rsa key being added (client and/or server side console messages, more in a next article), most of the time simply agree if requested to.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: