Skip to content

Instantly share code, notes, and snippets.

@valosekj
Last active September 27, 2022 06:45
Show Gist options
  • Save valosekj/ab8c32cf11d59c48afebba813fd86845 to your computer and use it in GitHub Desktop.
Save valosekj/ab8c32cf11d59c48afebba813fd86845 to your computer and use it in GitHub Desktop.
Configuration of `ssh` connection #blog

Configuration of ssh connection

Unix and MacOS

Let's say we want to configure an ssh connection between machine alpha and beta.

  1. Go to your home folder at machine alpha:
$ cd ~
  1. Run the ssh-keygen command:
$ ssh-keygen

The command will ask you for two things:

  1. Location of the keys; enter the full path (e.g., /home/<user>/.ssh/<user@machine>
  2. Passphrase; enter it.

The command will create two keys: private (<user@machine>) and public <user@machine>.pub.

Note - the .ssh directory must have drwx------ permissions; the private key must have -rw------- permissions; and the public key must have -rw-r--r-- permissions. You can modify the permission chmod command.

  1. Move the public key (with .pub extension) to the directory /home/<user>/.ssh/ on machine beta (e.g. using USB key)

Note - if the /home/<user>/.ssh/ directory does not exist on machine beta, create it by mkdir command. Again, permissions must be drwx------.

  1. Go to the .ssh directory and copy the content of the public key into the authorized_keys2 file:
$ cat <user@machine>.pub >> authorized_keys2
  1. Go back to the machine alpha and create a config file in the /home/<user>/.ssh/ directory by your favourite text editor (nano, vim, etc.):
$ cd ~
$ cd .ssh
$ nano config

The content of the config file should look like this:

Host <beta>
       User <user>
       Identityfile ~/.ssh/<user@machine>

Note - the config file must have -rw-r--r-- permissions.

Windows

Let's say we want to configure an ssh connection between Windows machine win and UNIX machine unix.

  1. On the win, download and install Putty application.

  2. Open PuttyGen (part of Putty) and generate RSA public and private keys.

Note - you should consider to set a passphrase.

  1. Move the public key to the UNIX machine unix and save it to /home/<user>/.ssh/

  2. Make sure that the public key has -rw-r--r-- permissions.

  3. Convert the public key to OpenSSH format, details here:

$ ssh-keygen -i -f publicKeyRSA  > publicKeyRSA_pub
  1. Copy the content of the public key into the authorized_keys2 file:
$ cat <user@machine>.pub >> authorized_keys2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment