Skip to content

SSH security

Filip Krzyżanowski edited this page Nov 15, 2022 · 1 revision

SSH login via your public key

1. Create .ssh directory in your user home directory

sudo mkdir /home/fkrzski/.ssh

2. Put your ssh key into authorized_keys file

You need to copy your SSH key from your local computer!

Option 1: echo - copy your SSH key and put in public_key_string place

sudo echo public_key_string >> /home/fkrzski/.ssh/authorized_keys

Option 2: nano - copy yous SSH key and put it into file created by nano

sudo nano /home/fkrzski/.ssh/authorized_keys

Press CTRL + SHIFT + V for paste, next CTRL + X and Y for exit with save.

It's all! Now you can log in using your key.

SSH Configuration

All things below are setting up in this file.
Fast line change in nano: CTRL + SHIFT + -, next type line number and press ENTER.

sudo nano /etc/ssh/sshd_config

After any changes you need to restart your SSH service

sudo systemctl restart ssh

Disable password login

# Line 84 
UsePam no

# Add this line at the bottom
PasswordAuthentication no

Disable root login

# Line 122 
PermitRootLogin no

Change SSH port

# Line 15 
Port 123
Clone this wiki locally