Server with SSH Key only

Date : 18-04-2025

Open PowerShell (Start Menu → type "PowerShell", then open it).

Run this command to create a new key:


ssh-keygen

You’ll see this prompt:


Enter file in which to save the key (/c/Users/YourName/.ssh/id_rsa):
  1. Just press Enter to accept the default location.

Then:


Enter passphrase (empty for no passphrase):
  1. You can leave it empty (just press Enter), or set a passphrase if you want more security.

It will say:


Your identification has been saved...
Your public key has been saved...


Add to Server

  1. SSH into your server, then:

sudo nano /root/.ssh/authorized_keys
  1. Paste the copied key into a new line.
  2. Save and exit (Ctrl + X, then Y, then Enter).
  3. Restart SSH (optional, usually not needed unless configs changed):

sudo systemctl restart ssh



SSHD config



Include /etc/ssh/sshd_config.d/*.conf

Port xxxx

LogLevel DEBUG3

RSAAuthentication yes

LoginGraceTime 30

MaxAuthTries 3

PubkeyAuthentication yes

AuthorizedKeysFile .ssh/authorized_keys

PermitEmptyPasswords no

KbdInteractiveAuthentication no

UsePAM yes

X11Forwarding yes

PrintMotd no

ClientAliveInterval 300 # Disconnect idle sessions

ClientAliveCountMax 2 # Max allowed idle sessions

AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

PermitRootLogin prohibit-password

PasswordAuthentication no