How to correctly set file permissions for SSH keys

#ssh #cli #security

| File                    | Permission (octal) | Permission (string) |
|------------------------ | ------------------ | ------------------- |
| .ssh (folder)           | 700                | drwx------          |
| id_rsa (private key)    | 600                | rw------            |
| ir_rsa.pub (public key) | 644                | rw-r-r-             |
  1. Use the following command to set the file permissions so that only you can read the file:
chmod 600 <private_key>
chmod 644 <public_key>
  1. Set the permisison of the .ssh directory to 700:
chmod 700 ~/.ssh
  1. connect to the remote server:
ssh -i <private_key> <user>@<ip_address>