Secure Shell (SSH) is an essential tool for system administrators, developers, and anyone managing remote servers. With SSH remote access, you can securely connect to a remote machine, execute commands, transfer files, and perform administrative tasks. In this article, we’ll explore 10 common SSH commands that you should be using today.
1. Connecting to a Remote Server
The most basic SSH command is used to connect to a remote server:
ssh user@remote_hostReplace user with your username and remote_host with the server’s IP address or domain name.
2. Connecting with a Specific Port
By default, SSH uses port 22, but you can specify a different port if necessary:
ssh -p 2222 user@remote_hostThis is useful if the SSH server is configured to run on a non-standard port.
3. Using SSH Keys for Authentication
Instead of using a password, you can authenticate with an SSH key:
ssh -i /path/to/private_key user@remote_hostGenerating an SSH key can be done with:
ssh-keygen -t rsa -b 4096This improves security and eliminates the need to enter a password every time.
4. Running Commands on a Remote Server
You can execute a single command on a remote server without opening an interactive session:
ssh user@remote_host "ls -l /var/www/html"This is useful for quick administrative tasks.
5. Copying Files with SCP
Secure Copy Protocol (SCP) allows you to transfer files between local and remote machines:
scp file.txt user@remote_host:/remote/directory/To copy a directory recursively:
scp -r /local/directory user@remote_host:/remote/directory/6. Copying Files with rsync
An alternative to SCP is rsync, which is more efficient for syncing files:
rsync -avz /local/directory user@remote_host:/remote/directoryIt minimizes data transfer by sending only the differences between files.
7. Setting Up SSH Tunneling
SSH tunneling allows you to securely forward network traffic. To create a local tunnel:
ssh -L 8080:localhost:80 user@remote_hostThis forwards traffic from your local port 8080 to the remote server’s port 80.
8. Reverse SSH Tunneling
Reverse tunneling lets a remote server access your local machine:
ssh -R 9090:localhost:22 user@remote_hostThis is useful for accessing a system behind a firewall.
9. Multiplexing SSH Connections
If you frequently connect to the same server, you can speed up SSH by enabling multiplexing:
ssh -o ControlMaster=yes -o ControlPath=~/.ssh/socket user@remote_hostThis reduces authentication overhead for multiple SSH sessions.
10. Terminating an SSH Session
To close an SSH session, simply type:
exitOr use the escape sequence:
~.This is helpful when the connection becomes unresponsive.


