root@zengyue:/home/yuanGit# git remote -v
origin https://github.com/seventeen71/yuan (fetch) #1
origin https://github.com/seventeen71/yuan (push) #2
origin git@github.com:seventeen71/yuan.git (push) #3
1、#2处的地址都是以https开头的,表示https传输,意味着你每次都要输入讨厌的username、password
作者本人的已经设置好了ssh传输,在#3处:地址是git开头则表示是git协议
提示:完全设置好push模式的话应该是这样
root@zengyue:/home/yuanGit# git remote -v
origin https://github.com/seventeen71/yuan (fetch)
origin git@github.com:seventeen71/yuan.git (push) #4
4处这样当你git push origin master时就不需要输入讨厌的密码了,下面讲如何去设置
root@zengyue:~/.ssh# ls
id_rsa id_rsa.pub
如果不存在id_rsa id_rsa.pub 两个文件的话:
Creates a new ssh key using the provided email # Generating public/private rsa key pair.
Enter file in which to save the key (/home/zengyue/.ssh/id_rsa):
这儿让你确认密钥目录,直接Enter回车就好:
Enter same passphrase again: [Type passphrase again]
接着让你输入及确认密码,然后就生成了密钥对。
出现下面提示说明OK了
Your public key has been saved in /home/zengyue/.ssh/id_rsa.pub.
The key fingerprint is: # ............ your_email@youremail.com
现在你可以在你的 ~/.ssh 目录看是否有id_rsa id_rsa.pub 两个文件
root@zengyue:~/.ssh# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbCLmkVonQAFjAgQVY7vH86NIsgw1kDV3dDYRXdmWoYSZ3gY4OEgzCqm8GWXRr+wNFUsSwhMmUabtEfRGGKlP/z2TBMzXFkcJ18zLAWXtgWWUH73tVfxXg+sdFpKhY0ppDYdU9Amk8ljVsge8+pKHVluk0ReBNtFsbp1w/seyrfUqsjigsnQHWeSPBns3CD7hs++7BXW5Mv4SH+ap30N+2tFBlqSuzitwLJCFed9isSFq2UQ4wiX25rs+eYpSloMY9kClMVVYuXN860EKCyF5V1ThS/TOcMoxDhGclDBoItS/oeTDGwopSTrsm5CFyUJFAd3qDYJ+yVy5fycVYfb6x youre@email.com
2.2.2 登陆你的github帐户。点击你的头像,然后
Settings -> 左栏点击 SSH and GPG keys -> 点击 New SSH key
2.2.3 将复制的公钥粘贴到key文本域,title随便起名,再点击Add key
2.2.4 然后回到linux下确认:命令 ssh -T git@github.com
root@zengyue:~/.ssh# ssh -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not # provide shell access. 看到这个你就成功了。
2.2.5 调整remote url
命令 git remote -v 查看,详细见文章开头
root@zengyue:/home/yuanGit# git remote -v
origin https://github.com/seventeen71/yuan (fetch)
origin https://github.com/seventeen71/yuan (push)
如果你的是这样,意思就是现在只有https传输,还需要输入username /password
输入命令:
git remote set-url origin git@github.com:[你的账户]/[你的github仓库].git
如下图进入你的仓库,点击1处,然后出现在2处的就是git协议地址了,
复制它拼接到命令git remote set-url origin 后面
git remote set-url origin git@github.com:someone/repository.git
11
12 [remote "origin"]
13 url = git@github.com:s--enten--/--an.git
14 fetch = +refs/heads/*:refs/remotes/origin/*
15 pushurl = git@github.com:s--enten--/--an.git.git
16 [branch "master"]
17 remote = origin
18 merge = refs/heads/master
当然你还可以使用git remote --help
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote set-url --push origin <你的github仓库url>
这样去设置解决也是可以哒!
当然如果你遇到如下问题:去我这篇博客找吧!
执行git clone git@github.com:accountName/repository.git命令时不出错,
运行git push时出错,提示如下
Permission denied(publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.