10 Essential SSH Command Shortcuts and Tricks for Linux Users

mahabub.devs3
Mahabubur Rahman
Published on Apr, 08 2025 2 min read 0 comments
Text Image

SSH (Secure Shell) is a powerful tool for securely accessing remote systems. Mastering a few handy shortcuts and tricks can significantly improve your workflow. Here are 10 useful SSH command tips you should know.

1. Quick SSH Login

Instead of typing:

ssh username@hostname -p port_number  

Use a shorter format:

ssh user@host -p port

2. Execute a Single Command Remotely

Run a command without entering an interactive session:

ssh user@host 'ls -l /var/www'  

Example:

ssh user@host 'ls -l /var/www'  

3. SSH with a Different Private Key

If you use multiple SSH keys, specify one with -i:

ssh -i ~/.ssh/custom_key user@host  

4. Disable Host Key Checking (For Scripts)

Bypass host verification (useful for automation, but less secure):

ssh -o StrictHostKeyChecking=no user@host  

5. SSH Tunneling (Port Forwarding)

Forward a local port to a remote server:

ssh -L local_port:remote_host:remote_port user@host  

6. SCP – Securely Copy Files Over SSH

Copy files from local to remote:

scp file.txt user@host:/path/to/destination  

Download from remote to local:

scp user@host:/remote/file.txt /local/path  

7. SFTP – Secure File Transfer

Start an interactive SFTP session:

sftp user@host  

8. Escape Sequences in SSH

Press ~ + ? during an SSH session to see available escape sequences.

~. – Terminate the session immediately.

~^Z – Background SSH.

9. Reuse SSH Connections for Faster Logins

Add this to ~/.ssh/config to speed up repeated logins:

Host *  
  ControlMaster auto  
  ControlPath ~/.ssh/sockets/%r@%h-%p  
  ControlPersist 600  

10. Exit SSH Without Closing the Session

Use -f to run SSH in the background after authentication:

ssh -f user@host sleep 10  

Bonus: SSH Config File Shortcuts

Simplify frequent connections by editing ~/.ssh/config:

Host myserver  
  HostName server.example.com  
  User myuser  
  Port 2222  
  IdentityFile ~/.ssh/my_key  

Now just run:

ssh myserver  

Final Thoughts

These SSH shortcuts and tricks can save time and streamline remote server management. Whether you're tunneling ports, reusing connections, or automating commands, mastering SSH will make you a more efficient sysadmin or developer.

 

 

0 Comments