SSH
Contents
SSH (Secure Shell)
SSH (Secure Shell) is a cryptographic network protocol that allows secure communication between two networked devices. It is most commonly used to log into remote systems and execute commands over an encrypted connection. SSH is a foundational tool in system administration, server management, and remote file transfers.
SSH replaces older, insecure protocols like Telnet and rlogin by encrypting all data exchanged between the client and server, including passwords, commands, and file transfers.
Key Features
- **Encrypted communication** – Prevents eavesdropping and man-in-the-middle attacks
- **Remote shell access** – Run commands on remote systems
- **Port forwarding/tunneling** – Securely forward ports between systems
- **Public key authentication** – Log in without passwords using cryptographic keys
- **File transfer support** – Via built-in tools like `scp` and `sftp`
Default Port
- SSH operates on **TCP port 22** by default.
Common Usage
SSH is used for:
- Managing remote Linux or Unix-based servers
- Accessing seedboxes, cloud instances, and VPS
- Securely copying files between machines
- Tunneling traffic for applications or databases
- Automation with shell scripts or cron jobs
Basic SSH Command
<syntaxhighlight lang="bash"> ssh username@hostname </syntaxhighlight>
Example:
<syntaxhighlight lang="bash"> ssh user@192.168.1.100 </syntaxhighlight>
This connects to the host at IP `192.168.1.100` using the specified username.
SSH Key Authentication
SSH supports login via a key pair (public/private):
1. Generate keys:
<syntaxhighlight lang="bash"> ssh-keygen -t rsa -b 4096 </syntaxhighlight>
2. Copy the public key to the remote server:
<syntaxhighlight lang="bash"> ssh-copy-id user@hostname </syntaxhighlight>
3. Now, you can connect without entering a password.
File Transfer with SSH
- **SCP** – Secure copy files:
<syntaxhighlight lang="bash"> scp file.txt user@hostname:/remote/path/ </syntaxhighlight>
- **SFTP** – Interactive secure file transfer:
<syntaxhighlight lang="bash"> sftp user@hostname </syntaxhighlight>
SSH Configuration File
User-specific SSH options can be set in:
<syntaxhighlight lang="bash"> ~/.ssh/config </syntaxhighlight>
Example:
<syntaxhighlight lang="text"> Host seedbox
HostName your.seedbox.com User yourusername Port 22
</syntaxhighlight>
Now you can connect using:
<syntaxhighlight lang="bash"> ssh seedbox </syntaxhighlight>
Security Tips
- Use **SSH keys** instead of passwords
- Disable root login (`PermitRootLogin no`) in the SSH configuration
- Change the default port from 22 to another port
- Use a firewall (e.g., ufw or iptables)
- Monitor for brute-force attempts with tools like fail2ban
Related Tools
- OpenSSH – The most common SSH implementation for Unix-like systems
- PuTTY – A popular SSH client for Windows
- WinSCP – GUI-based file transfer over SSH for Windows