Top Basic Linux SSH Commands That You Should Know

If you’re new to Linux, chances are you’ll be using the SSH protocol to connect to remote servers…

Linux ssh commands



Top Basic Linux SSH Commands That You Should Know

Top Basic Linux SSH Commands That You Should Know

SSH (Secure Shell) is the backbone of remote server management. It allows you to connect securely to your Linux servers, transfer files, run commands, and manage infrastructure without being physically present. For anyone working with VPS or dedicated servers, SSH is an essential tool. In this guide, we’ll explore the top basic Linux SSH commands you should know to work efficiently and securely.


πŸ”‘ 1. Connecting to a Remote Server

The most common use of SSH is connecting to a server:

ssh username@server_ip

If the SSH service runs on a custom port:

ssh -p 2222 username@server_ip

πŸ“‚ 2. Copying Files with scp

Use scp (Secure Copy) to move files between local and remote systems:

# Upload
scp local.txt username@server_ip:/home/username/

# Download
scp username@server_ip:/home/username/remote.txt .

πŸ“¦ 3. Synchronizing Files with rsync

rsync is faster than scp because it transfers only differences:

rsync -avz /local/folder username@server_ip:/remote/folder

πŸ‘€ 4. Running Remote Commands

Execute commands directly without logging in:

ssh username@server_ip "df -h"

πŸ”’ 5. Using SSH Keys for Authentication

Keys are safer than passwords:

# Generate
ssh-keygen -t rsa -b 4096

# Copy to server
ssh-copy-id username@server_ip

πŸ“ 6. Editing Remote Files

Once connected, edit configs directly:

nano /etc/ssh/sshd_config
vim /etc/nginx/nginx.conf

πŸ” 7. Tunneling and Port Forwarding

Securely forward local ports:

ssh -L 8080:localhost:80 username@server_ip

πŸ› οΈ 8. Multiplexing Connections

Reuse SSH sessions for speed:

ssh -M -S /tmp/ssh-socket username@server_ip
ssh -S /tmp/ssh-socket -O check username@server_ip

πŸ” 9. Checking SSH Version

ssh -V

πŸ“œ 10. Viewing Last Logins

last -a | head -n 10

πŸ‘€ 11. Switching Users

su - anotheruser

Or connect as root:

ssh root@server_ip

πŸšͺ 12. Closing Idle Sessions

Auto-close idle sessions via /etc/ssh/sshd_config:

ClientAliveInterval 300
ClientAliveCountMax 2

🧹 13. Killing a Frozen SSH Session

Type:

~.

πŸ“– 14. Saving Configurations

Create a ~/.ssh/config file:

Host myserver
    HostName 192.168.1.10
    User root
    Port 2222

Then just run:

ssh myserver

⚑ 15. Using SFTP

SFTP offers an interactive file transfer session:

sftp username@server_ip
sftp> put local.txt
sftp> get remote.txt

βœ… Conclusion

SSH is more than just a login method; it’s a complete toolkit for secure server administration. By learning these commands, you’ll improve efficiency, security, and reliability when managing your Linux servers. At WeHaveServers.com, all of our VPS and dedicated servers come with full SSH root access, so you can put these commands into practice immediately.


❓ FAQ

What is SSH used for?

SSH (Secure Shell) is used to securely log in to servers, execute commands, and transfer data over encrypted connections.

What port does SSH use?

By default, SSH uses port 22, but many admins change it for security reasons.

Is SSH safe?

Yes, SSH encrypts all communication, making it safe. Using key-based authentication improves security further.

How do I exit an SSH session?

You can type exit or press Ctrl+D. If frozen, type ~..

Can I use SSH on Windows?

Yes. Windows 10+ has a built-in SSH client, or you can use PuTTY.


Leave a Reply

Your email address will not be published. Required fields are marked *