Overview¶
SSH (Secure Shell) is a protocol used for secure remote login and communication over a network. It is widely used for:
-
Remote server access
-
Secure file transfer
-
System administration
-
Cybersecurity operations
SSH Installation¶
Install SSH Client and Server¶
Explanation
-
openssh-client→ allows you to connect to remote systems -
openssh-server→ allows others to connect to your system
SSH Usage¶
Basic Login¶
Example¶
Explanation
-
Connects to remote machine
-
Prompts for password authentication
Specify Custom Port¶
Example¶
SSH Server Security Hardening¶
Edit SSH Configuration¶
Disable Root Login¶
Find and modify:
Explanation
-
Prevents direct root login
-
Reduces attack surface
Limit Sessions¶
Explanation
- Controls number of concurrent sessions
Restart SSH Service¶
Lock Root Account¶
Explanation
-
Disables root password login
-
Adds an extra security layer
SSH Key-Based Authentication¶
Generate SSH Key Pair¶
Explanation
-
Creates public and private keys
-
Files generated:
-
id_rsa→ private key -
id_rsa.pub→ public key
-
Copy Public Key to Server¶
Explanation
-
Adds public key to server’s
authorized_keys -
Enables passwordless login
Disable Password Authentication¶
Edit SSH config:
Change:
Restart service:
Login Using Private Key¶
Explanation
- Uses private key instead of password
Secure Private Key¶
Explanation
-
Restricts access to owner only
-
Required for SSH to accept the key
File Transfer Using SCP¶
Copy File to Remote Server¶
Example¶
Explanation
- Transfers file securely over SSH
Copy Directory Recursively¶
SSH Brute Force Protection with Fail2Ban¶
Enable Fail2Ban at Startup¶
Navigate to Configuration Directory¶
Create Custom Configuration¶
Example Configuration¶
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 3600
ignoreip = 127.0.0.1
Explanation¶
-
enabled→ activate protection -
port→ service port -
maxretry→ allowed failed attempts -
bantime→ ban duration (seconds) -
ignoreip→ trusted IP addresses
Restart Fail2Ban¶
Practical Workflow¶
Secure SSH Setup¶
apt install openssh-server
ssh-keygen -t rsa
ssh-copy-id user@IP
vim /etc/ssh/sshd_config
systemctl restart sshd
Transfer File Securely¶
Important Notes¶
-
Always disable root login for security
-
Prefer key-based authentication over passwords
-
Protect private keys with strict permissions
-
Use Fail2Ban to prevent brute-force attacks
-
Restart services after configuration changes
Summary Table¶
| Command | Purpose |
|---|---|
ssh |
Remote login |
ssh -p |
Custom port login |
ssh-keygen |
Generate keys |
ssh-copy-id |
Copy public key |
scp |
Secure file transfer |
chmod 400 |
Secure private key |
systemctl |
Manage SSH service |
fail2ban |
Protect against brute force |
Conclusion¶
SSH is a critical tool for secure remote access. Proper configuration and hardening ensure:
-
Secure communication
-
Protection against unauthorized access
-
Efficient system management
Mastering SSH improves both system administration and cybersecurity capabilities.