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.10Output
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
| Option | Description | Example |
|---|---|---|
| -p port | Specify a custom port number | ssh -p 2222 user@host |
| -i file | Use a specific private key file | ssh -i ~/.ssh/id_rsa user@host |
| -v | Verbose mode for debugging | ssh -v user@host |
| -C | Enable compression | ssh -C user@host |
| -X | Enable X11 forwarding | ssh -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.