0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use SSH Command in Linux: Simple Guide

Use the ssh command in Linux to securely connect to a remote server by specifying the username and server address like ssh user@hostname. This command opens a secure shell session where you can run commands on the remote machine.
📐

Syntax

The basic syntax of the ssh command is:

  • ssh [options] user@hostname

Here, user is the username on the remote machine, and hostname is the IP address or domain name of the remote server. Options can modify behavior like port number or identity file.

bash
ssh [options] user@hostname
💻

Example

This example shows how to connect to a remote server with username alice at IP 192.168.1.10. It opens a secure shell session where you can run commands remotely.

bash
ssh alice@192.168.1.10
Output
alice@192.168.1.10's password: Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-50-generic x86_64) alice@192.168.1.10:~$
⚠️

Common Pitfalls

Common mistakes when using ssh include:

  • Typing the wrong username or hostname causes connection failure.
  • Not having the correct permissions or keys set up leads to authentication errors.
  • Forgetting to specify a custom port if the server uses one other than the default port 22.

Always verify your details and check network connectivity.

bash
Wrong: ssh user@wronghost
Right: ssh user@correcthost

Wrong: ssh -p 22 user@host  # If server uses a different port, this fails
Right: ssh -p 2222 user@host  # Specify correct port
📊

Quick Reference

OptionDescriptionExample
-p portSpecify a custom port numberssh -p 2222 user@host
-i fileUse a specific private key filessh -i ~/.ssh/id_rsa user@host
-vVerbose mode for debuggingssh -v user@host
-CEnable compressionssh -C user@host
-XEnable X11 forwardingssh -X user@host

Key Takeaways

Use ssh user@hostname to connect securely to a remote Linux server.
Specify options like -p for custom ports or -i for identity files as needed.
Check username, hostname, and network connectivity to avoid connection errors.
Use verbose mode -v to troubleshoot SSH connection issues.
SSH provides a secure encrypted channel to run commands remotely.