# Passwordless SSH access to server

When you implement server for your dev, staging, production, etc. environments it happens that you have to access each of those servers when you need to config something or check the execution logs. Instead of having to input a password each time you access a server, you can skip that step by following this procedre.

## In a Nutshell

1. Generate an SSH key pair on the developer PC if one does not already exist (e.g. `~/.ssh/id_ed25519.pub`).

1) Copy the public key to the remote server to `~/.ssh/authorized_keys` (each user on remote server has a file with this name). The helper command `ssh-copy-id` can do this automatically and only needs to be installed on the machine from which it is executed (typically the developer PC).
2) when you want to revoke the access you can delete the public key from `~/.ssh/authorized_keys`

## In detail

Generate a key pair if needed:

```bash
ssh-keygen -t ed25519
```

Typical files:

```text
~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub
```

Install the public key for a remote user:

```bash
ssh-copy-id user@server
```

This adds the public key to:

```text
/home/alice/.ssh/authorized_keys
```

- If there is no `ssh-copy-id` in dev-pc you can copy the contents of .pub file to `~/.ssh/authorized_key` on remote server manually

Note that SSH keys grant access to a specific user account, not to the entire server.

For a server with multiple users:

```text
/home/alice/.ssh/authorized_keys
/home/bob/.ssh/authorized_keys
/home/deploy/.ssh/authorized_keys
```

If your public key only exists in Alice's file:

```bash
ssh alice@my-server   # works
ssh bob@my-server     # fails
```

To allow access as multiple users, add the public key to each user's:

```text
~/.ssh/authorized_keys
```

To revoke access, remove the corresponding line from:

```text
~/.ssh/authorized_keys
```

on the target account.

🤖Keep growing your apss and always be learning, dev-san 🥷
