Deploy ssh key to the github repository but get permission denied
井民全, Jing, mqjing@gmail.com
1. Weird Situation
To deploy a public ssh key to GitHub for the management of your source repository is quite easy. However, did you ever get a weird situation that everything was set done, but you cannot pull the code? Whatever, you check and check, re-generate the key, again and again, you always get the permission denied message, like this.
Fig. The permission denied message after git clone command.
1.1. Root Cause
When you copy the public/private key from the other computer, the permission of the key changed. That caused the issue.
1.2. Solution
Set the correct permission to the keys.
Private key: 600
Public key: 660
1.3. Reference
2. Detail
2.1. Deploy key to your repository
Step 1: GitHub, [Your project] -> [Settings] -> [Deploy keys]
Fig. The repository settings.
Fig. The Deploy keys function.
Step 2: Deploy key
Generate your public/private key pair
Command: ssh-keygen -t rsa
Fig. Generated key-pair.
Add new deploy key: Paste your public key to the github
cat .ssh/id_rsa.pub
Fig. Add new deploy key.
2.2. Note
2.2.1. Error in SSH directory permissions
1, The .ssh directory permissions should be 700 (drwx------). The public key (.pub file) should be 644 (-rw-r--r--). The private key (id_rsa) on the client host, and the authorized_keys file on the server, should be 600 (-rw-------). If you don't follow this, you will get this.
Fig. Permission denied if the private key permission is not 600.