Git add ssh authentication

来源:互联网 发布:linux强制停止sh 编辑:程序博客网 时间:2024/06/06 09:42

密码认证 和 公私钥 只是2种不同的方式而已。

但是每次pull or push 代码的 时候 都要输入密码,让人很头疼。所以还是用公钥私钥的验证方便。

2台机器:local & remote

//在local上生成公钥私钥对:cd ~/.ssh && ssh-keygen//在.ssh目录下建一个文件夹(名字随意,比如remote_keys)用来单独存放 刚才生成的公私密钥对:mkdir ~/.ssh/remote_keysmv ~/.ssh/id_rsa* ~/.ssh/remote_keys///在.ssh/config 文件中 指明哪个域名对应哪个私钥echo "Host remote.net">~/.ssh/config && echo "IdentityFile ~/.ssh/remote_keys/id_rsa" >> ~/.ssh/config//上面三句可以写成一句:mkdir ~/.ssh/remote_keys && mv ~/.ssh/id_rsa* ~/.ssh/remote_keys/  && echo "Host remote.net">~/.ssh/config && echo "IdentityFile ~/.ssh/remote_keys/id_rsa" >> ~/.ssh/config//到这里,local的部分做完了,下面是remote的部分,你该把你的公钥给人家了。//登录到remote,编辑~/.ssh/authorized_keys文件,把local的公钥即id_rsa.pub里的内容追加到这个文件里。//这样,公钥,私钥的映射就建立起来了。
(千万不要在terminal里直接拷贝粘贴,应使用cat >>)



原创粉丝点击