Rakesh Jain
Rakesh Jain

@devops_tech

27 Tweets 20 reads Jul 25, 2023
Mastering SSHπŸ”’!
A Thread explaining 15 most crucial SSH commands πŸ‘‡
What is SSH!πŸš€
SSH (Secure Shell) is a secure network protocol that enables users to access & manage remote machines securely over an encrypted connection. It provides a safe & encrypted way to execute commands, transfer files, & perform various tasks on remote servers. #SSH
1/ πŸ”‘To connect to a remote machine, use:
ssh username@remote_host
Replace "username" with your account & "remote_host" with the server's IP/hostname. #SecureConnections #RemoteAccess
2/πŸ—οΈ Did you know? You can use SSH keys for authentication, avoiding passwords. Generate your key pair with:
ssh-keygen -t rsa
Then copy your public key to the remote server's ~/.ssh/authorized_keys file.
#KeyAuthentication #SecurityMatters
3/🌐 To execute commands on the remote server, simply:
ssh username@remote_host command
It'll run "command" on the server & show the output locally. Handy, right?
#RemoteCommands #SysAdminLife
4/ πŸ“ Copying files between local & remote machines? Rely on SCP (SSH Copy):
scp /path/to/local_file username@remote_host:/path/to/destination
Securely transfer files without fuss!
#FileTransfer #SSH
5/πŸ”„ Need to forward ports for secure access to services? Use SSH port forwarding:
ssh -L local_port:destination_host:remote_port username@jump_host
Now access destination_host:remote_port via localhost:local_port.
#PortForwarding #NetworkingTricks
6/⏲️ Running a long task? Prevent disconnection by keeping SSH session alive:
ssh -o ServerAliveInterval=60 username@remote_host
SSH will send a "keep-alive" signal every 60 seconds. No more annoying timeouts!
#StayConnected #ProductivityHacks
7/πŸšͺ Change the default SSH port for added security:
sudo nano /etc/ssh/sshd_config
Modify "Port 22" to a custom port, then restart SSH service. Impenetrable! πŸ”’
#SecurityFirst #CustomPort
8/ 🚧 Enable X11 forwarding to run GUI applications remotely:
ssh -X username@remote_host
Now, when you run GUI apps, they'll display on your local machine!
#GUIoverSSH #RemoteApps
9/ πŸ—„οΈ To securely store passwords, use SSH-agent:
eval "$(ssh-agent)" ssh-add /path/to/private_key
No more entering passwords repeatedly! πŸ™Œ
#SSHAgent #PasswordSecurity
10/ πŸ”’ Disallow root login via SSH to bolster security:
sudo nano /etc/ssh/sshd_config
Set "PermitRootLogin" to "no", then reload SSH. Elevate privileges smartly!
#RootLoginDenied #SecurityTips
11/ πŸšͺ Limit user access with SSH chroot:
sudo nano /etc/ssh/sshd_config
Use "ChrootDirectory" to restrict users to their home directories. Isolate & control!
#UserIsolation #AccessControl
12/ πŸ” Search remote files like a pro with "grep" over SSH:
ssh username@remote_host "grep -r 'search_term' /path/to/directory"
Search for 'search_term' in files located at '/path/to/directory' on the remote host.
#RemoteSearch #SysAdminTricks
13/ πŸ“œ Edit files on the fly using "sed" over SSH:
ssh username@remote_host "sed -i 's/old_text/new_text/g' /path/to/file"
Replace 'old_text' with 'new_text' in the specified file. Changes applied remotely!
#SSHsed #RemoteEditing
14/ πŸ“Š Monitor resource usage with "top" remotely:
ssh username@remote_host "top"
Get real-time insights into processes, CPU, and memory usage on the remote machine.
#RemoteMonitoring #SysAdminLife
15/ πŸ”„ Synchronize local and remote directories using "rsync" over SSH:
rsync -avz -e "ssh" /path/to/local_dir username@remote_host:/path/to/destination
Efficiently transfer files between local and remote locations.
#RSync #DataSync
Time for Bonus πŸ’°πŸ˜
1/ 🐞 Enable debug mode to troubleshoot SSH connection issues:
ssh -v username@remote_host
Verbose mode displays detailed connection process. Unravel the mysteries!
#SSHDebugMode #Troubleshooting
2/πŸ” Authenticate with PEM file (private key) instead of passwords:
ssh -i /path/to/key.pem username@remote_host
Boost security & login with your PEM file. No more passwords! πŸš€
#PEMfile #SecureAuthentication
3/ πŸ“ Copy files using PEM file with SCP:
scp -i /path/to/key.pem /path/to/local_file username@remote_host:/path/to/destination
Combine security & file transfer in one go! πŸ”’
#SCPPemFile #SecureCopy
4/ πŸ›‘οΈ Use PEM file with Rsync for secure synchronization:
rsync -avz -e "ssh -i /path/to/key.pem" /path/to/local_dir username@remote_host:/path/to/destination
Safeguard data while syncing directories. πŸ”
#RSyncPEM #SecureDataSync
5/πŸ¦πŸ’» SSHAliases: Create aliases for quick access to servers. Edit bash/zsh profile file.
πŸ’» alias server1='ssh user@example[dot]com'
πŸ’» alias server2='ssh user@example[dot]com'
πŸ”’ #Aliases #SSH
6/ πŸ¦πŸ’»SSHFS: Mount remote directories over SSH.
Install 'sshfs' & mount like:
πŸ’» sshfs user@example[dot]com:/remote/path /local/mount/point
7/ πŸ¦πŸ’»SSHKnownHosts: Manage known hosts to prevent man-in-the-middle attacks.
πŸ’»nano ~/.ssh/known_hosts
Go forth and master these advanced SSH commands! πŸ’ͺ Happy remote management!
#SSHAdvanced #SysAdminTools
(Note: Always exercise caution when executing commands that modify or transfer data remotely.)
Retweet the thread if you find it useful. Thanks!

Loading suggestions...