简介:介绍如何配置和使用 Git 的 SSH 密钥进行身份验证,以实现无密码提交代码到远程仓库。
在 Git 中,SSH 密钥用于身份验证,以在不需要输入用户名和密码的情况下将代码提交到远程仓库。下面是配置和使用 Git SSH 密钥的步骤:
按三次回车,这将生成一个名为
ssh-keygen -t rsa -C "your-email@example.com"
id_rsa 的私钥和一个名为 id_rsa.pub 的公钥。私钥应妥善保管,不要与他人分享。公钥则可以安全地分享给任何人。id_rsa.pub)。将
git config --global user.name "Your Name"git config --global user.email "your-email@example.com"
Your Name 和 your-email@example.com 替换为你自己的名字和电子邮件地址。这将设置 Git 的默认用户名和电子邮件地址。在
git clone ssh://github.com/user/repo.gitgit push origin master
git clone 和 git push 命令中,将 github.com/user/repo.git 和 origin master 替换为你自己的远程仓库地址和分支名称。这将使用 SSH 密钥连接到远程仓库并将代码推送到指定的分支。git config --global user.name 和 git config --global user.email 命令来设置这些凭证。