$ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y
-weight: 600;">sudo adduser yourusername
-weight: 600;">sudo adduser yourusername
-weight: 600;">sudo usermod -aG -weight: 600;">sudo yourusername
-weight: 600;">sudo usermod -aG -weight: 600;">sudo yourusername
-weight: 600;">sudo nano /etc/ssh/sshd_config
-weight: 600;">sudo nano /etc/ssh/sshd_config
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh
ssh-keygen -t rsa -b 4096
ssh-keygen -t rsa -b 4096
ssh-copy-id yourusername@your_server_ip
ssh-copy-id yourusername@your_server_ip
PasswordAuthentication no
PasswordAuthentication no
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install ufw
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install ufw
-weight: 600;">sudo ufw default deny incoming
-weight: 600;">sudo ufw default allow outgoing
-weight: 600;">sudo ufw default deny incoming
-weight: 600;">sudo ufw default allow outgoing
-weight: 600;">sudo ufw allow ssh # Or your custom SSH port
-weight: 600;">sudo ufw allow http
-weight: 600;">sudo ufw allow https
-weight: 600;">sudo ufw allow ssh # Or your custom SSH port
-weight: 600;">sudo ufw allow http
-weight: 600;">sudo ufw allow https
-weight: 600;">sudo ufw -weight: 500;">enable
-weight: 600;">sudo ufw -weight: 500;">enable
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban
-weight: 600;">sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
-weight: 600;">sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local - Disable Root Login: Logging in directly as the root user (the superuser with ultimate privileges) is dangerous. Create a regular user account and grant it -weight: 600;">sudo privileges. First, create a new user: -weight: 600;">sudo adduser yourusername Then, add them to the -weight: 600;">sudo group: -weight: 600;">sudo usermod -aG -weight: 600;">sudo yourusername After this, log out and log back in as yourusername.
- Change Default SSH Port: The default SSH port is 22. Attackers often scan for this port. Changing it to a non-standard port can reduce automated attack attempts. Edit the SSH configuration file: -weight: 600;">sudo nano /etc/ssh/sshd_config Find the line #Port 22 and change it to your desired port (e.g., Port 2222). Uncomment the line by removing the #. After changing the port, you'll need to -weight: 500;">restart the SSH -weight: 500;">service: -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh Remember to connect using ssh yourusername@your_server_ip -p 2222 in the future.
- Use SSH Key-Based Authentication: Instead of passwords, use SSH keys. This involves generating a pair of cryptographic keys: a public key that you place on the server and a private key that you keep on your local machine. This is akin to having a unique, unbreakable lock and key for your server's door, far more secure than a simple written password. Generate keys on your local machine: ssh-keygen -t rsa -b 4096 Copy your public key to the server: ssh-copy-id yourusername@your_server_ip Finally, -weight: 500;">disable password authentication in /etc/ssh/sshd_config: PasswordAuthentication no Restart SSH: -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh - Install UFW (if not present): -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install ufw
- Set Default Policies: Deny all incoming traffic and allow all outgoing traffic. -weight: 600;">sudo ufw default deny incoming
-weight: 600;">sudo ufw default allow outgoing
- Allow Necessary Ports: -weight: 600;">sudo ufw allow ssh # Or your custom SSH port
-weight: 600;">sudo ufw allow http
-weight: 600;">sudo ufw allow https
- Enable UFW: -weight: 600;">sudo ufw -weight: 500;">enable You will be prompted to confirm. - Install Fail2ban: -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban
- Configure: Fail2ban's main configuration file is /etc/fail2ban/jail.conf. However, it's best practice to create a local configuration file to avoid overwriting changes during updates. -weight: 600;">sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local Edit jail.local using -weight: 600;">sudo nano /etc/fail2ban/jail.local. You can -weight: 500;">enable specific jails (e.g., for SSH) and adjust parameters like bantime (how long an IP is banned) and findtime (the window to detect too many failures). - /var/log/auth.log: Authentication logs.
- /var/log/syslog: System messages.
- /var/log/apache2/access.log and /var/log/apache2/error.log (for Apache web servers). - Keep Web Server Software Updated: Ensure Apache, Nginx, or other web server software is patched.
- Use HTTPS: Encrypt communication between clients and your server using SSL/TLS certificates. Let's Encrypt provides free certificates.
- Sanitize User Input: Prevent injection attacks (like SQL injection or Cross-Site Scripting) by validating and sanitizing all data submitted by users.