git 配置公钥与私钥

git 配置公钥与私钥

生成密钥:
1.首先在cmd里面运行 ssh-keygen -t rsa -C "xxxxxxxx@qq.com" 双引号里是邮箱.会在用户下产生.ssh文件夹
这个 ssh-keygen 位于git安装目录下的 /usr/bin

将公钥拿出去:
2. 进入文件管理器目录为 C:\Users\计算机用户名\.ssh的id_rsa.pub将内容复制到 码云(没有账号就注册,然后 设置 安全设置 SHH公钥 )添加即可
3.然后在码云中创建仓库.创建仓库后,就会有仓库的相关信息.

git配置用户名与邮箱

git config --global user.name "xxxxxxxx" //这个是码云的用户名
git config --global user.email "xxxxxxxxxxx@qq.com"//第一步中的邮箱名
To configure Git to use an SSH private key for authentication, you need to ensure that your SSH keys are properly set up and that Git is configured to use them. Below are the steps to achieve this: 1. **Generate SSH Keys (if not already generated):** If you don't have an existing SSH key pair, you can generate one using the `ssh-keygen` command. This will prompt you to specify a file to save the key and optionally set a passphrase: ```bash ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` After generating the keys, you will have two files: a private key (e.g., `~/.ssh/id_rsa`) and a public key (e.g., `~/.ssh/id_rsa.pub`). 2. **Add the Public Key to Your Git Server:** For platforms like GitHub, GitLab, or Bitbucket, you need to add the contents of your public key file (`~/.ssh/id_rsa.pub`) to your account's SSH keys section. This allows the server to recognize your machine during authentication. 3. **Configure SSH in `~/.ssh/config` (Optional but useful for multiple keys):** If you're working with multiple Git servers or accounts, it's beneficial to define specific keys in the SSH configuration file. Here’s how you can specify different private keys for different hosts: ```plaintext # GitLab.com server Host gitlab.com RSAAuthentication yes IdentityFile ~/.ssh/private-key-filename-01 # Private GitLab server Host gitlab.company.com RSAAuthentication yes IdentityFile ~/.ssh/private-key-filename ``` Make sure to replace `private-key-filename-01` and `private-key-filename` with the actual names of your private key files [^1]. 4. **Start the SSH Agent and Add Your Private Key:** The SSH agent manages your private keys and helps in authenticating without repeatedly entering your passphrase. Start the agent and add your key with these commands: ```bash eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa ``` Replace `id_rsa` with the filename of your private key if it differs. 5. **Test the SSH Connection:** To verify that everything is set up correctly, try connecting to the Git server via SSH: ```bash ssh -T git@github.com ``` A successful connection should return a welcome message from the service (e.g., GitHub), confirming that SSH is working as expected. 6. **Set Git Configuration for User Information:** Ensure that Git knows your user name and email address for commit attribution: ```bash git config --global user.name "Your Name" git config --global user.email "your_email@example.com" ``` 7. **Use SSH URLs When Cloning Repositories:** When cloning a repository, always use the SSH URL instead of HTTPS. For example: ```bash git clone git@github.com:username/repository.git ``` By following these steps, Git will be configured to use your SSH private key for secure, password-less authentication when interacting with remote repositories [^2].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值