> For the complete documentation index, see [llms.txt](https://sarpers-organization.gitbook.io/ctftricks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sarpers-organization.gitbook.io/ctftricks/_chapter-intro-7/ssh/key-based-authentication/trick-0299.md).

# SSH Authentication with Private Key

***

If you obtain an SSH private key, you can use it to authenticate to the target server. Save the key content to a local file, commonly named `id_rsa` or `id_rsa.pem`.

Then, set appropriate permissions for the file so SSH accepts it. The private key file should have permissions 600 (read/write for owner, no permissions for others). This is because if others can read your private key, they can impersonate you.

```bash
chmod 600 id_rsa
```

If the permissions are too open, for example, 0644, SSH will issue a warning such as "WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions ... are too open." It is recommended that your private key files are NOT accessible by others. If you don't set the permissions correctly, ssh will refuse to use it and will fall back to password authentication (if enabled).

Finally, use the `ssh` command with the `-i` flag to specify the path to your private key file to connect.

```bash
ssh -i /path/to/your/key.pem user@host
```

Replace `/path/to/your/key.pem` with the actual path to your saved private key file (like `id_rsa`), `user` with the username on the target server, and `host` with the target server's IP address or hostname.
