SSH (Secure Shell) is a secure communication protocol that allows a user to access and control a remote computer over a network. Unlike older protocols like Telnet or Rlogin, SSH encrypts every piece of data, preventing attackers from spying on login credentials and commands.
SSH typically uses TCP port 22 and is supported by all major Linux distributions.
Basic Syntax of the SSH Command
To connect to a remote server, use:
ssh [username]@[hostname or IP address]
Here, Replace [username] with your remote server username, and [hostname or IP address] with the server's hostname or IP address.
Example:
ssh [email protected]
Output:
Installing SSH
To install SSH, you simply install the OpenSSH package, which provides both the client and server components.
On Ubuntu/Debian:
sudo apt update
sudo apt install openssh-client openssh-servers
On CentOS/Fedora/RHEL:
sudo dnf install openssh-clients openssh-server
Start and enable the SSH service:
sudo systemctl start sshd
sudo systemctl enable sshd
Check status:
sudo systemctl status sshd
Output:
Given below the examples by using SSh Command.
[Example 1]: Connect to a Remote Server Using SSH
- Username > vboxuser
- Server IP > 10.0.2.15
ssh [email protected]
- If it’s your first time connecting, SSH will ask to verify the server’s fingerprint. Type yes, press Enter, and then enter the user’s password.
- Once authenticated, you will be logged into the remote machine and can run commands just like a local terminal.
Output:
[Example 2]: Using SSH Key Authentication
SSH keys offer better security than passwords.
- Generate keys on your local machine
ssh-keygen
- Copy your public key to the remote server:
ssh-copy-id username@server_ip
- Now you can log in without entering a password:
ssh username@server_ip
Common SSH Options
| Option | Purpose | Example |
|---|
-p | Connect to a custom SSH port | ssh -p 2222 user@host |
-v | Enable detailed debugging output | ssh -v user@host |
-C | Enable compression | ssh -C user@host |
-4 | Force IPv4 | ssh -4 user@host |
-6 | Force IPv6 | ssh -6 user@host |
-X | Forward GUI applications | ssh -X user@host |
- These options help troubleshoot issues, improve performance, and customize the connection.
Before You Connect: Requirements
To successfully connect to a remote Linux machine using SSH, ensure the following:
1. The remote server is reachable
- The machine must be switched on and connected to a network.
2. You have valid login credentials
- A username and password OR an SSH key pair.
3. SSH service is running on the server
- The OpenSSH server must be installed and active.
4. Firewall allows SSH traffic
- Port 22 (or the configured custom port) should be open.
5. SSH installed on your local system
- Most Linux systems already include an SSH client.
How SSH Secures Communication
SSH uses multiple layers of cryptography:
1. Symmetric Encryption
- Uses one shared key for encrypting and decrypting the session.
2. Asymmetric Encryption
- Uses a public/private key pair for authentication and key exchange.
3. Hashing
- Ensures message integrity - any tampering is immediately detected.
- Together, these make SSH extremely secure for remote access.
Explore
Linux/Unix Tutorial
5 min read
Getting Started with Linux
Installation with Linux
Linux Commands
Linux File System
Linux Kernel
Linux Networking Tools
Linux Process
Linux Firewall
Shell Scripting & Bash Scripting