How to set Deploy keys to deal with error: Permission denied (publickey)?
在不熟悉的環境下使用 git
指令進行 commit
、push
、pull
等等的指令可能會遇到權限問題而無法使用:
On branch master
nothing to commit, working directory clean
Warning: Permanently added the RSA host key for IP address 'xxx.xx.xxx.x' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
網路上依據不同情況有很多不同解決方式,本範例單純解決因為本機權限而造成的無法使用 git
相關動作的情形且為 MacOS
環境。
1.於本機產生 ssh key
打開 Terminal 輸入下述:
ssh-keygen -t rsa -b 4096 -C "github帳號mail"
ex: ssh-keygen -t rsa -b 4096 -C “test.developer@gmail.com“
2.設定路徑與密碼
可以都直接enter 或 yes,不用輸入任何路徑或是密碼。
3.將 key 加入 ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
4.把 SSH Key 複製下來
vim ~/.ssh/id_rsa.pub
EX:
ssh-rsa AFAAB3NzaC1yc2EAAAADAQABAAACAQDgyUQwYXGwERW/s4/0DVThkXFl1LHNss7Kz8gxMpieLCDF+5MZ+gl7/qewfq2/6aNfoJKizfUHX7ZBklm2Jj46OF+80zRtMhyJ8cI7oHWklVvUZ0csWHZVwN5PIxJ3/WtDtO/zD9OBF/6rCOVq9m1TBkWAgJL4ElnbECkkmR69Ujtpf/xgWQsqtHxPjfogTn5FdpPvmP/zQvTII7WwAZvCZNanX29DGnzuZ/XvdQ82xJuGK8pOPffi5lD760lybaVrYtfd+50aMrhGGrTwDE6J8ES3Ou9TzKA8ctm/12kCRXeM5QGaH5tqxGkl3cGU6kpPjMLq2s9fQwEQnv7tAz4lSmPoBNaDSqIWUzBBHq+6oqR0rtPtfwAXb3qVh20hpSgoDg5gMo3QelP6Q5YV7WaPE9kCd3TU8sVdXY8An2t6P0Zto6K4B9CAUalVLZVqU/kCz38iA/vq03iz3v+P3nAY7/WOUYQbXefN7lEBV5kpQfcWMMCl/6UiB7JzvtNUH7Q5bDkyONyzMct75aHeUVz4v6nR4O6mhvKJM0sBHvPWuHiD5CsJ9SHLE/quHRcnaM8ToeNYDUVeHEBl8SQNipv9SaU7TO7C2/lZCRzgFGQV9BKb9KA9V+8/wxF0Qn6j9GRI8YBOclaB6NOzoNEJfg6Kh2VYWzxBPiZ1noz+L6x7Ew== clh.developer@gmail.com
5.將 key 加入 Github Deploy Key
選取你要處理的 repo 進入 Setting
→ Deploy Key
→ Add deploy key
→ 取名字加入上面複製的 ssh key → 完成