Open In App

SSH Command in Linux

Last Updated : 19 Nov, 2025
Comments
Improve
Suggest changes
18 Likes
Like
Report

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:

image---2025-11-19T172157603

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:

image---2025-11-19T174109287

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:

image---2025-11-19T172157603

[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
image---2025-11-19T174718712

Common SSH Options

OptionPurposeExample
-pConnect to a custom SSH portssh -p 2222 user@host
-vEnable detailed debugging outputssh -v user@host
-CEnable compressionssh -C user@host
-4Force IPv4ssh -4 user@host
-6Force IPv6ssh -6 user@host
-XForward GUI applicationsssh -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