SSH

Setup SSH authentication on a Linux server from Linux/Windows

Generate SSH Keys

ssh-keygen

Copy SSH Key to Remote Linux Device

From Linux:

ssh-copy-id <user>@ # -p <port-number> (optional)

OR

cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'umask 0077; mkdir -p .ssh; cat >> .ssh/authorized_keys && echo "Key copied"'

From Windows:

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh <hostname> "cat >> .ssh/authorized_keys"

(Optional) SSH Config

Create .ssh/config file

Host MyServer
  HostName <hostname>
  User <user>
  IdentityFile 

Host blabla
  HostName <hostname>
  User <user>
  IdentityFile ~/.ssh/id_rsa_blabla

You can then connect easily to ssh like this:

ssh MyServer

If you use VSCode, it will also detect your SSH Hosts from config file.

You might encounter an issue with VSCode where it'll ask you everytime the Remote Platform, here's how to fix it

  1. Press F1 and open user Settings (JSON)

  2. Add your remote hosts like this:

"remote.SSH.remotePlatform": {
    "grenx": "linux",
    "ServMaison": "linux"
  }

Last updated