Knowledge

How to connect to a server with the ssh command

#CommandLine

Connect to a remote server with the ssh command, including custom ports, key files, the host key prompt, SSH config aliases, and verbose debugging.

Published by Mark van Eijk on June 23, 2026 · 2 minute read

  1. Connecting with ssh
  2. Custom port
  3. Using a specific key file
  4. The first-connection prompt
  5. Host aliases with ~/.ssh/config
  6. Debugging with -v
  7. Where to go next

Connecting with ssh

SSH is how I reach almost every server I work with. The basic form is the command, the user, and the host:

ssh jane@203.0.113.10

You can use a hostname instead of an IP, and SSH will resolve it:

ssh jane@app.example.com

If you don't pass a key explicitly, SSH tries the default keys in ~/.ssh. If you don't have a key yet, generate one first: create SSH keys with ssh-keygen.

Custom port

SSH listens on port 22 by default. Many servers move it elsewhere for security. Use -p (lowercase) to specify the port:

ssh -p 2222 jane@app.example.com

Using a specific key file

Cloud providers often hand you a .pem file. Point SSH at it with -i (identity file):

ssh -i ~/.ssh/aws-key.pem ubuntu@203.0.113.10

If the key has loose permissions, SSH refuses to use it. Fix it with chmod 400 ~/.ssh/aws-key.pem so only you can read it.

The first-connection prompt

The first time you connect to a host, SSH shows the server's fingerprint and asks:

The authenticity of host 'app.example.com' can't be established.
ED25519 key fingerprint is SHA256:abc123...
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type yes and SSH stores the fingerprint in ~/.ssh/known_hosts. On later connections it checks silently. This is expected; it only warns you again if the fingerprint changes.

Host aliases with ~/.ssh/config

Typing long commands gets old fast. I keep a ~/.ssh/config so I can connect with a short alias:

Host prod
    HostName app.example.com
    User jane
    Port 2222
    IdentityFile ~/.ssh/aws-key.pem

Now the whole thing collapses to:

ssh prod

Every flag above can live in the config, which keeps it out of your muscle memory and your shell history.

Debugging with -v

When a connection misbehaves, -v (verbose) shows exactly what SSH is doing: which keys it offers, what the server accepts, and where it stops. Add more vs for more detail:

ssh -v prod
ssh -vvv prod

If you hit Permission denied (publickey), I've written up the causes and fixes here: SSH permission denied (publickey).

Where to go next

Once you can connect, you can do more than open a shell. Run a single command without a full session with run a command over SSH, and move files with scp over SSH.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

Argument list too long (Bash: /bin/rm)

Connect to a remote server with the ssh command, including custom ports, key files, the host key prompt, SSH config aliases, and verbose debugging.

Read more →

How to install Composer packages locally

Connect to a remote server with the ssh command, including custom ports, key files, the host key prompt, SSH config aliases, and verbose debugging.

Read more →