SSH Command in Linux

Last Updated : 1 Jun, 2026

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 vboxuser@10.0.2.15

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-server

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 vboxuser@10.0.2.15
  • 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

These options help troubleshoot issues, improve performance, and customize the connection.

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

Before You Connect: Requirements

To successfully connect to a remote Linux machine using SSH, ensure the following:

  • The server must be switched on and connected to a network.
  • You should have valid login credentials
  • The OpenSSH server must be installed and active.
  • Port 22 (or the configured custom port) should be open on your firewall.

How SSH Secures Communication

SSH uses multiple layers of cryptography:

  • Symmetric Encryption: Uses one shared key for encrypting and decrypting the session.
  • Asymmetric Encryption: Uses a public/private key pair for authentication and key exchange.
  • Hashing: Ensures message integrity - any tampering is immediately detected.
Comment

Explore