How to connect to a server with the ssh command - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

How to connect to a server with the ssh command
===============================================

### [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

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](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 2 minute read

1. [Connecting with ssh](#content-connecting-with-ssh)
2. [Custom port](#content-custom-port)
3. [Using a specific key file](#content-using-a-specific-key-file)
4. [The first-connection prompt](#content-the-first-connection-prompt)
5. [Host aliases with ~/.ssh/config](#content-host-aliases-with-sshconfig)
6. [Debugging with -v](#content-debugging-with--v)
7. [Where to go next](#content-where-to-go-next)

[\#](#content-connecting-with-ssh "Permalink")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](/generate-ssh-keys-ssh-keygen).

[\#](#content-custom-port "Permalink")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

```

[\#](#content-using-a-specific-key-file "Permalink")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.

[\#](#content-the-first-connection-prompt "Permalink")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.

[\#](#content-host-aliases-with-sshconfig "Permalink")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.

[\#](#content-debugging-with--v "Permalink")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 `v`s 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)](/ssh-permission-denied-publickey).

[\#](#content-where-to-go-next "Permalink")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](/run-command-over-ssh), and move files with [scp over SSH](/copy-files-over-ssh-scp).

### 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!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

- [Argument list too long (Bash: /bin/rm)](https://rocketeersapp.com/knowledge/argument-list-too-long)
- [How to install Composer packages locally](https://rocketeersapp.com/knowledge/install-composer-packages-locally)
- [How to send GET and POST requests with curl](https://rocketeersapp.com/knowledge/curl-post-get-api-requests)
- [Essential Linux command line basics for developers](https://rocketeersapp.com/knowledge/linux-command-line-basics)
- [How to search file contents with grep](https://rocketeersapp.com/knowledge/search-files-grep-command)
- [The complete guide to the curl command](https://rocketeersapp.com/knowledge/curl-command-complete-guide)

 [View all 21 articles →](https://rocketeersapp.com/knowledge/command-line)
