Alecks ๐ŸŒฑ

Securing ssh on your linux server.

ยท Alecks

This post is made for debian based linux distros

Non-root account for logins / Disable root login.

Disabling the ability to login as root helps with many automated bots that brute-force ssh into your server, start by making a new user with any username you wants

adduser kuma

Then add it to the list of sudoers

usermod -aG sudo kuma

Using SSH keys over plaintext passwords.

SSH Keys are both more convenient and more secure than a regular plaintext password, especially the default one set by your hosting provider.

Generate an ssh key using PuttyGen and paste it on a new line in /home/<your_username>/.ssh/authorized_keys

Updating your SSH configuration.

This process can differ depending on your host, but for most servers the ssh config is located in /etc/ssh/sshd_config, in the file you want to change the following values

PasswordAuthentication no
PubkeyAuthentication yes
PermitRootLogin no

Changing these config vaulues will

Run the command below to apply the motifications

sudo systemctl restart ssh

NTFY notifcations on ssh login.

Adding these lines to your /etc/profile file will send a request to your chosen ntfy server when any user logs in via ssh

if [ -n "$SSH_CLIENT" ]; then

NTFY="${USER}@$(hostname -f) from $(echo $SSH_CLIENT|awk '{print $1}')"

curl -u :<ntfy_api_key> -s -H "Title: SSH Login" -d "$NTFY" -L  "https://ntfy.exaple.com/ssh" > /dev/null

fi

Modify to add your own api key and change the url to your ntfy server

You can also find an example on the ntfy docs here (Didn’t work for me)

#linux #servers #ssh #security