This is definitively not the first post on the Internet about this, but I keep needing this and I think I really needed my own version of the post.

You are on your local machine (mine is a Mac) and I want to connect to a remote server (Ubuntu or CentOS in this scenario).

Let’s assume the remote host is called remotehost and you want to connect as remoteuser.

## Generate a Pair of Authentication Keys

Open a terminal and generate a pair of authentication keys. Do not enter a passphrase.

$ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/jgp/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/jgp/.ssh/id_rsa. Your public key has been saved in /Users/jgp/.ssh/id_rsa.pub. The key fingerprint is: 77:c3:79:a8:98:50:92:6b:5f:5b:43:68:a9:b3:59:6a jgp@Jean-Georgess-MacBook-Pro.local The key's randomart image is: +--[ RSA 2048]----+ | | | . | | o . | | + + o | | + S * X . | | . O B * + | | B o | | E= . | | .+ | +-----------------+  If you get: $ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jgp/.ssh/id_rsa):
Overwrite (y/n)? n


It means you already have a set of keys and you do not want to erase them. Go directly to step 2.

## Setup Remote Host

If nobody has done it before: now use ssh to create a directory ~/.ssh as user remoteuser on remotehost. (The directory may already exist, which is fine):