User Tools

Site Tools


ubuntu_22.04:pub_key

SSH public key authentication

SSH public key authentication is a four-step process:

1. Generate a private and public key, known as the key pair. The private key must be stored securely on the local machine.

2. Copy the corresponding public key to the remote server to enable key-based authentication.

3. The remote server stores the public key in the authorized_keys file and marks it as authorized.

4. Access the remote server by proving ownership of the corresponding private key during login.

Follow the sections below for the breakdown of every step in this process.

Generate a private and public key

Use the mkdir command to create the .ssh directory and set the correct permissions (700):

  mkdir -p ~/.ssh && chmod 700 ~/.ssh

Generate the SSH key pair:

  ssh-keygen

Add Public Key to User

Access the remote server and create the .ssh directory with the correct permissions (700):

  ssh [username]@[hostname_or_ip] "mkdir -p ~/.ssh && chmod 700 ~/.ssh"

Use the touch command to create the authorized_keys file in the .ssh directory and set its permissions to 600:

  touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys

On Linux, you can use the following command to copy the public key directly to the remote server:

  ssh-copy-id [username]@[hostname_or_ip]

Note : if the private Key is for use with Putty you have to load the key file with the private key and save it with Puttgen

ubuntu_22.04/pub_key.txt · Last modified: 2025/02/13 13:44 by 195.53.121.100