Network and remote access

Command ssh

Connect to a remote server

Linux · Bash examples · commands run on the selected server

When to use ssh

Use ssh to open a protected remote shell or run one command on a server. Confirm the server identity before accepting a host key, then choose the account, authentication key and port explicitly when defaults do not apply.

Syntax

ssh [OPTIONS] [USER@]NODE [COMMAND]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-p PORT
SSH server port.
-i KEY
Private key for authentication.
-L SPECIFICATION
Local port forwarding.

Usage examples

Open server shell

ssh deploy@server.example.com

An interactive shell opens as the named account after authentication succeeds.

Use a key and a different port

ssh -p 2222 -i ~/.ssh/id_ed25519 deploy@server.example.com

A specific private key and nondefault port are selected for the connection.

Run one command

ssh deploy@server.example.com 'uptime'

The server executes the uptime command and sends its output back; no persistent interactive shell is opened.

Notes and limitations

  • When connecting for the first time, check the server key fingerprint using a trusted channel; changing a known key requires verification.
  • The terminal opens on the remote node. Do not transmit private options and passwords to logs or public command lines.

Common questions and troubleshooting

How do I investigate Permission denied (publickey)?

Check the account name, chosen key, server authorization and key-file permissions. Compare verbose client diagnostics without sharing secrets or blindly changing server policy.

What should I do when the host key changes?

Stop and verify the new fingerprint through a trusted channel. A rebuilt server can change keys, but so can an intercepted connection.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man ssh.