SSH is a powerful tool for remote server management, allowing secure communication between systems. Knowing essential commands can greatly enhance your productivity.
How do you establish an SSH connection?
Establishing an SSH connection is fundamental for remote server management. You can initiate a connection using the command ssh user@host. Replace user with your username and host with the server's IP address or domain name.
For example, to connect as the user john to a server at 192.168.1.10, you would use:
ssh john@192.168.1.10This command prompts for the user's password unless key-based authentication is set up. Key-based authentication is more secure and eliminates the need for a password. To set it up, generate a key pair using ssh-keygen and copy your public key to the server with ssh-copy-id user@host.
Establishing an SSH connection is as simple as using ssh user@host.How can you transfer files over SSH?
Transferring files over SSH is commonly done using scp (secure copy protocol). The syntax is scp source_file user@host:destination_path. This command securely copies the file from your local machine to the server.
For instance, to copy a file named data.txt to the home directory of john on 192.168.1.10, use:
scp data.txt john@192.168.1.10:~Similarly, you can download files from the server by reversing the order: scp user@host:source_file destination_path.
While most SSH clients like Termius and JuiceSSH require you to manually enter these commands, ShellSage simplifies this with real SFTP support, allowing drag-and-drop file transfers directly from your phone.
Use scp to transfer files securely over SSH.How do you execute remote commands?
Executing commands on a remote server without logging in interactively is a powerful feature of SSH. Use ssh user@host 'command' to run a command directly. This is useful for automating tasks or quickly checking system status.
For example, to list the contents of /var/www on a remote server, use:
ssh john@192.168.1.10 'ls /var/www'Remember, the command must be enclosed in single quotes to execute correctly. This technique is especially helpful in scripts where manual login is impractical.
What is SSH port forwarding?
SSH port forwarding, also known as tunneling, allows you to securely forward network traffic between your local and remote machines. It's useful for accessing services behind a firewall or encrypting traffic between client and server.
There are two types of port forwarding: local and remote. Local forwarding forwards a local port to a remote service. For instance, to forward local port 8080 to a remote web server on port 80, use:
ssh -L 8080:localhost:80 user@hostRemote forwarding, on the other hand, forwards a remote port to a local service. This is done with -R instead of -L.
While Termius supports basic port forwarding, ShellSage's blast-radius preview helps you understand the impact of these commands before executing them, reducing the risk of misconfigurations.
When should you use a reverse tunnel?
Reverse tunneling is useful when you need to access a local service from a remote machine, especially when the local machine is behind a firewall or NAT. It involves setting up a tunnel from the remote machine back to your local machine.
To create a reverse tunnel, use the -R option. For example, to access a local web server running on port 3000 from a remote server, use:
ssh -R 9000:localhost:3000 user@remote_hostThis command makes the local web server accessible on remote_host at port 9000. Reverse tunnels are powerful for remote access and troubleshooting.
Most mobile SSH clients, like Blink Shell, require manual setup for reverse tunnels. ShellSage simplifies it with voice input and AI to guide you through complex configurations.
Understanding these commands can significantly enhance your ability to manage servers effectively. Whether you're transferring files, running remote commands, or setting up tunnels, mastering SSH is crucial for developers and sysadmins.
⚡ Key takeaways
- ›SSH is essential for secure remote server management.
- ›Use <code>scp</code> for secure file transfers over SSH.
- ›SSH port forwarding enables secure access to remote services.

