我们一般用http的形式拉取代码。 ssh的好处就是不用每次输入密码,而且貌似会快丢丢,不知道是不是错觉。
一、本地生成密钥对; 二、设置github上的公钥; 三、修改git的remote url为git协议。
SSH 公钥默认储存在账户的主目录下的 ~/.ssh 目录。进去看看:
$ cd ~/.ssh $ ls authorized_keys2 id_dsa known_hosts config id_dsa.pub生成:
$ ssh-keygen -t rsa -C “your_email@youremail.com”
执行下:
[root@iZbp16x1iba3qb7a1cuu20Z bin]# ssh-keygen -t rsa -C "lixin" Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:xtPk6o3L...CfcOK7UCo lixin The key's randomart image is: +---[RSA 2048]----+ | ..o ..o . | | . o o.+ | | o . ++. | | +.o+ ..=.. | | . ++o.o o | | ..=o+o . | | o oE=o . | | . ooo=+. . | | .oo.o*oo=o | +----[SHA256]-----+直接粘贴进去就好了
================================================ 可以用git remote -v 查看你当前的remote url
$ git remote -v origin https://github.com/test1/test1.git (fetch) origin https://github.com/test1/test1.git (push)使用 git remote set-url 来调整你的url。
git remote set-url origin git@github.com:test1/test1.git完了之后,你便可以再用 git remote -v 查看一下。