Skip to main content

Connecting to a Remote Server

Use the ssh command to establish a connection to a remote host:
# Connect using your local machine username (if it matches the remote)
ssh <remote-host-ip-address/name>

# Specify a different username
ssh <username>@<remote-host-ip-address/name>

# Connect on a non-default port
ssh -p <port-number> <username>@<remote-host-ip-address/name>

# Show verbose output for debugging
ssh -v <username>@<remote-host-ip-address/name>

# Run a single command on the remote host (connection closes when done)
ssh <username>@<remote-host-ip-address/name> <command-to-run>
ssh <username>@<remote-host-ip-address/name> ls -la

Parameters

ParameterDescriptionExample
-pPort number2222
-vVerbose output for more connection details
To simplify repeated connections, create a host-specific configuration file using SSH client config aliases.

known_hosts

When you SSH to a server for the first time, a fingerprint is displayed and you are prompted to confirm the connection. Accepting it saves the fingerprint to your local ~/.ssh/known_hosts file, so you are not prompted again on future connections.
The known_hosts file is automatically created in your local ~/.ssh/ directory the first time you accept a server’s fingerprint.
This mechanism helps prevent man-in-the-middle attacks — if a server’s fingerprint changes unexpectedly, SSH will warn you before connecting.

Build docs developers (and LLMs) love