Skip to main content

Enable ssh login with a public key

image.png

Introduction

it is more secure and easier to login to a server over ssh if you place your public key on this server. This how-to shows in simple steps how to do this.

Generate keys

You only have to do this one time. You can and should reuse your public key for all ssh-servers.

Step 1 - creating SSH key pair

Make sure you are in your home directory.

ssh-keygen -t rsa
If you want so secure the access to your key with password, enter a password. Otherwise press enter two times.

Step 2 - Copying the SSH public key to the ssh server

The real magic happens here:

ssh-copy-id <username>@<ssh-server>
Basically this command copies the file .ssh/id_rsa.pub to your ssh-server. You can either use an ip address or an FQDN (e.g. hcloud.simmy.ch) as ssh-server

Connect to the server

ssh <username>@<ssh-server>

 https://www.linuxshelltips.com/passwordless-ssh-login/