Secure Shell (SSH) is a powerful protocol used for secure remote administration of Linux and Unix-like systems. This guide covers essential SSH command-line tools, their use cases, and advanced features to help you manage remote systems efficiently.
READ ALSO: Advanced SSH Techniques: A Deep Dive Into Secure Remote Access
ssh user@remote_host
This command establishes an SSH connection with the specified remote host. Replace user with the actual username and remote_host with the IP address or hostname of the remote server.
ssh -p 2222 user@remote_host
If the SSH server is running on a non-default port (default is 22), use the -p flag to specify the correct port.
ssh user@remote_host "ls -la"
Executes ls -la on the remote server and returns the output.
ssh-keygen -t rsa -b 4096
ssh-copy-id user@remote_host
Generating and copying SSH keys allows password-less authentication, improving security and convenience.
scp file.txt user@remote_host:/remote/path/
scp -r directory/ user@remote_host:/remote/path/
SCP (Secure Copy Protocol) allows secure file transfer between local and remote machines.
sftp user@remote_host
sftp> put localfile.txt
sftp> get remotefile.txt
SFTP (SSH File Transfer Protocol) provides an interactive mode for transferring files securely.
ssh -L 8080:localhost:80 user@remote_host
Forwards local port 8080 to the remote server’s port 80, useful for accessing web services securely.
ssh -R 9090:localhost:22 user@remote_host
Allows remote users to connect to the local SSH service via port 9090 on the remote machine.
ssh -D 1080 user@remote_host
Creates a SOCKS proxy on port 1080, useful for browsing securely through the SSH tunnel.
ssh -o ServerAliveInterval=60 user@remote_host
Prevents SSH connections from timing out due to inactivity.
ssh -M -S ~/.ssh/controlmastersocket -o ControlPersist=10m user@remote_host
Allows multiple SSH connections to the same host without re-authenticating.
ssh -f user@remote_host -N
Runs SSH in the background without executing a command, useful for port forwarding.
~/.ssh/configCustomize SSH behavior per host:
Host myserver
HostName remote_host
User user
Port 2222
IdentityFile ~/.ssh/id_rsa
This simplifies SSH connections by allowing ssh myserver instead of typing full details each time.
ssh -X user@remote_host
Allows GUI applications to run on a remote server and display on the local machine.
/etc/ssh/sshd_config and set PermitRootLogin no.Port 2222 in /etc/ssh/sshd_config to reduce automated attacks.PasswordAuthentication no in sshd_config.systemctl status sshd
Ensures the SSH daemon is running.
ssh -vvv user@remote_host
Enables verbose output to diagnose connection issues.
sudo systemctl restart sshd
Applies configuration changes and restarts the SSH service.
Mastering Linux SSH command-line tools enhances system administration efficiency, security, and automation. Whether you need basic connectivity, secure file transfers, or advanced tunneling, SSH provides a robust set of features for managing remote systems effectively.
Advanced SSH Techniques: A Deep Dive into Secure Remote Access Secure Shell (SSH) is a…
Introduction The DNS Cluster feature set is flexible to allow for an array of configurations.…
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
This website uses cookies.