solution to git@github.com出现Permission denied (publickey)

  1. Create SSH key

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # change your path to .ssh file
    cd ~/.ssh
    # create new SSH key
    ssh-keygen -t rsa -b 4096 -C "your git email"
    # note that name of the file to save key should be "id_rsa"
    # if you use other name, it will reprot "Permission denied (publickey)." when "ssh -T git@github.com"

    # if you use other name, remember to add it
    ssh-add ~/.ssh/your_name
  2. Add SSH key to git

    You are supposed to find id_rsa and id_rsa.pub. The former is you SSH key.

    Create a new SSH key in your github and copy everything in id_rsa.pub to it.

  3. Test your connection with git

    ssh -T git@github.com

    If there is no bug report, you key is acceptable.