git 查看用户名和邮箱地址
$ git config user.email
$ git config user.name
运行命令来配置你的用户名和邮箱
$ git config --global user.email '' you@example.com''
$ git config --global user.name " you name"
(此用户名和邮箱是git提交代码时用来显示你身份和联系方式的,并不是github用户名和邮箱)
生成密钥对
SSH公钥默认存储在账户的主目录下的~/.ssh目录.
$ cd ~/.ssh
$ ls
id_rsa id_rsa.pub 有.pub后缀的文件就是公钥
如果没有这些文件,甚至连.ssh目录都没有, 可以用ssh-keygen来创建
$ ssh-keygen -t rsa -C "you email@example.com"
Enter file in which to save the key (/home/you/.ssh/id_rsa):
然后提示你输入密码,直接按enter就行;
密钥就生成了,大概就这样:
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@youremail.com
添加公钥到你的远程仓库
1. 查看你生成的公钥指令
$ cat ~/.ssh/id_rsa.pub
AAAAB3NzaC1yc2EAAAADAQABAAABAQC0X6L1zLL4VHuvGb8aJH3ippTozmReSUzgntvk434aJ/v7kOdJ/MTyBlWXFCR+
HAo3FXRitBqxiX1nKhXpHAZsMciLq8vR3c8E7CjZN733f5AL8uEYJA+YZevY5UCvEg+umT7PHghKYaJwaCxV7sjYP7Z6V7
9OMCEAGDNXC26IBMdMgOluQjp6o6j2KAdtRBdCDS/QIU5THQDxJ9lBXjk1fiq9tITo/aXBvjZeD+gH/Apkh/0GbO8VQLiYYm
NfqqAHHeXdltORn8N7C9lOa/UW3KM7QdXo6J0GFlBVQeTE/IGqhMS5PMln3 admin@admin-PC
登录你的github账号 点击你的头像 然后 Setting -> 左栏点击SSH and GPG keys -> 点击New SSH key
然后填写你的公钥
点击Add key
完成之后,验证这个key是不是正常工作:
$ ssh -T git@github.com
如果看到
Hi xxx! You've successfully authenticated, but GitHub does not # provide shell access. 代表设置成功了!