# Git push error - Add public key to github ###### tags: `Github` ### 錯誤訊息 ``` git@github.com: Permission denied (public key). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ``` ### 原因 1. 這個Repo是private的 2. Github沒有你電腦的public key ### 解法 產生電腦中的public key並且添加到Github setting內 步驟 1. 打開Git bash並輸入 ``` ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` 2. 接著會出現下列訊息 `Enter file in which to save the key (/home/YOUR_USER_NAME/.ssh/id_rsa):` 按下Enter 3. 接著要你輸入密碼,並且重複確認密碼 `Enter passphrase (empty for no passphrase):` `Enter same passphrase again: ` 4. 完成後,電腦的public key便會儲存在某個資料夾中,路徑請查看訊息 `Your public key has been saved in C:\***\xxxx/.ssh/id_rsa.pub` 5. 此後便使用cat指令查看這個檔案,輸入以下指令 `cat "C:\***\xxxx/.ssh/id_rsa.pub."` 6. 之後會出現public key如下 `` ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCpaUcHFgHs+h+dKledqqbdYtbU8q43NNhiaOL1508XD1+DmQDVpLV2bNI9ZZomqlh3nOkZ3IMbXzhrJNdK/nDH5RnKu0z/nob9+bgKJRyl0YMjNyDb1ICGt155Eix6mRHMTYlcEVkULQFfoPdeb3IvH2ICHMgm/PpHImSRxbtLfcBp9pUtdJ8bW+dsxZ9Bd/jZSPwx4QmUfGPkVhBUlcmE2tsrIicEa9yWLY7lGYdZeZN+KtVfNiYoRLOlKRAyhPP69TG9tU6XZ3GBJCVOysFK8vi9bAYOhMW6SwyLsTV+yc2GA4/ZmZQXZDkHpQznZM0O5bERrKLTWEJplSrXUXznNx2EdhDn8JaqCGYzS/TZ3a1tp5F0G8jM0BC9J5jj8c6iJh0NjJ1U3l2CgB6pB5wVh9L7toqNmybOzJ+nCTZ4Wq2NSSRq4xdxmEWFVKn9fp/YxXuJibC4J9iY7AFPAgBnqm3t0QXZ4iQ1/m2MnCTd+2lsG/Sfrr2gsRvPUWEL4IM <你的信箱> `` 7. 之後到Github中加入這串Key Github > Settings > SSH and GPG keys 8. 接著再重新push便可成功
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up