Basic SSH Client Usage
The SSH client enables secure connections to remote systems, execution of commands, and file transfers. This section explains how to connect to remote hosts, details the SSH command syntax, and outlines available authentication methods.
Connecting to Remote Hosts
The most common use of SSH is to establish a secure connection to a remote host. The syntax for a basic SSH connection is as follows:
$ ssh user@remote_host
- user: The username of the account being accessed on the remote machine.
- remote_host: The IP address or hostname of the remote server.
For example, to connect to a server with the IP address 192.168.1.100
using the username admin
:
$ ssh admin@192.168.1.100
If SSH is running on a non-standard port (anything other than the default port 22), the port can be specified using the -p
option:
$ ssh -p 2222 user@remote_host
Command Syntax and Options
The ssh
command offers various options to modify its behavior. Some of the most commonly used options include:
-p [port]: Specifies the port number to connect to on the remote host.
$ ssh -p 2222 user@remote_host
-i [identity_file]: Specifies the private key file for authentication. Refer to the Key-Based Authentication section for details on generating and using SSH keys.
$ ssh -i ~/.ssh/id_rsa user@remote_host
-L [local_port]:[remote_host]:[remote_port]: Sets up local port forwarding, allowing a port on the local machine to securely forward traffic to a specified port on the remote machine.
$ ssh -L 8080:localhost:80 user@remote_host
-R [remote_port]:[local_host]:[local_port]: Sets up remote port forwarding, allowing a remote machine to access local services.
$ ssh -R 9090:localhost:3306 user@remote_host
-C: Enables compression, which can improve performance when transferring large files or working over slow networks.
$ ssh -C user@remote_host
SSH User Authentication Methods
SSH supports multiple methods for user authentication. The two most commonly used are password authentication and public key authentication.
Password Authentication
Password authentication prompts the user to enter the account password after initiating the SSH connection. While simple to use, password authentication is less secure than key-based authentication. For stronger security, refer to the Key-Based Authentication section.
Example of password authentication:
$ ssh user@remote_host
user@remote_host's password:
Public Key Authentication
Public key authentication provides a more secure alternative to password-based login. Instructions for setting up key-based authentication can be found in the Key-Based Authentication section.
Understanding basic SSH client usage, including connecting to remote hosts and managing authentication, establishes the foundation for securely accessing and managing remote systems. More advanced topics, such as securing configurations and using port forwarding, will be explored in subsequent sections.