Connecting to a remote server via SSH

Use the ssh utility on your local machine to connect to a remote server via SSH. This applies to Linux, macOS, and Windows 10. Use Terminal under macOS and Linux to call the ssh utility. On Microsoft Windows 10, use PowerShell.

Basic syntax

ssh username@server_ip_or_hostname

For example:

ssh root@192.0.2.1

Connecting with an SSH key

If you use an SSH key pair for authentication, specify the path to the private key with the -i flag:

ssh -i /path/to/private_key username@server_ip_or_hostname

Connecting on a non-standard port

By default, SSH listens on port 22. If your server uses a different port, specify it with the -p flag:

ssh -p 2222 username@server_ip_or_hostname

First-time connection

When connecting to a server for the first time, you will be prompted to confirm the server's fingerprint:

The authenticity of host '192.0.2.1 (192.0.2.1)' can't be established.
ECDSA key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no)?

Type yes to proceed. The server's key will be saved in ~/.ssh/known_hosts.

Troubleshooting

  • Permission denied: Check that your username and password (or private key) are correct.
  • Connection refused: Verify the server IP, port, and that the SSH daemon is running.
  • Connection timed out: Check firewall rules and network connectivity.

On this page