Uncategorized

Connect to a server with an SSH key


Problem

Every time I want to connect to my server over SSH, I have to retype my password every single time.

In VS Code, with the “Remote Explorer” extension, it can get pretty annoying in the long run.

Solution

The solution is to use an SSH key. You just generate the key on your device, run a command to connect to your server over SSH, and that’s it, no more typing the password every time.

ssh-keygen -t ed25519

After creating the key, we connect to our server and add our key to it.

Windows

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@serveur -p 22 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"

Of course, replace “user@serveur” with your actual SSH user and server.

Linux

ssh-copy-id -p 22 user@serveur

Of course, replace “user@serveur” with your actual SSH user and server.