Hi this is a little Tutorial to how to setup a Linux Ubuntu Server and the security.
- Internet Connection
- Basic Knowledge of Linx Ubuntu
- A linux machine local or remote
- A computer for connect to the server
For a better protection all steps are important.
- color 🟥 important
- color 🟧 less important
- color 🟩 non important
sudo apt update && sudo apt upgrade -y ssh-keygen -t rsa -b 4096 -C "Email or Identifier"or
ssh-keygen -t ed25519 -C "Email or Identifier"- Based on the difficulty of factoring large numbers.
- Keys are larger (2048+ bits) for equivalent security.
- Slower for signing and verifying compared to modern algorithms.
- Common in legacy systems and applications requiring compatibility.
- Based on elliptic curve cryptography (specifically Curve25519).
- Smaller keys (256 bits) with high security and performance.
- Much faster signing and verification.
- Designed for modern use cases, with a focus on efficiency and resistance to side-channel attacks.
scp ~/.ssh/keyid.pub username@server:~/nameofuser_ed25519.pub
scp ~/.ssh/keyid.pub username@server:~/nameofuser_rsa.pub
cat ~/nameofuser_ed25519.pub >> ~/.ssh/authorized_keyschmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysrm ~/nameofuser_ed25519.pubsudo nano /etc/ssh/sshd_configsshd_config:
Port change it
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PermitRootLogin no
ChallengeResponseAuthentication yes
PasswordAuthentication no
AuthenticationMethods publickey, keyboard-interactive
UsePam yesif there is Include path like(Include /etc/ssh/sshd_config.d/*.conf) check the path to the config and remove any contradiction
sudo nano /etc/ssh/sshd_config.d/*.confsudo apt install ufwcheck if it's correctly installed
ufw versionor
sudo ufw versionssh = The SSH port previously configured ports = Ports you need to be opend in your machine
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw limit ssh
sudo ufw allow ports
sudo ufw enablesudo systemctl start ufw
sudo systemctl status ufwsudo apt install libpam-google-authenticatorsudo google-authenticatorScan the QR code with a TOTP app like Google Authenticator, Authy, or similar. Answer the questions to configure the behavior (e.g., if you want to allow multiple codes in case of time synchronization issues).
sudo nano /etc/pam.d/sshdsshd:
auth required pam_google_authenticator.sosudo apt install fail2bansudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.localjail.local:
ssh = The SSH port previously configured
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = -1
action = ufw-banCreate custom config fail2ban
sudo nano /etc/fail2ban/action.d/ufw-ban.confufw-ban.conf:
[Definition]
actionstart = ufw
actionstop = ufw
actionban = ufw insert 1 deny from <ip> to any
actionunban = ufw delete deny from <ip> to anysudo systemctl restart ssh/sshd
sudo systemctl restart fail2ban
sudo systemctl restart ufwsudo systemctl status ssh/sshd
sudo systemctl status fail2ban
sudo systemctl status fail2ban sshd
sudo systemctl status ufwssh -p Port user@hostnameI hope this helped you
💻💖 by xSpartan155x
