如何使用git终端

检查是否存在SSH密码

Before you generate an SSH key, you can check to see if you have any existing SSH keys.

Windows

  1. Open Git Bash.

  2. Enter ls -al ~/.ssh to see if existing SSH keys are present:

    $ ls -al ~/.ssh
    # Lists the files in your .ssh directory, if they exist
  3. Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following:
    • id_rsa.pub
    • id_ecdsa.pub
    • id_ed25519.pub

If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key.

If you see an existing public and private key pair listed (for example id_rsa.pub and id_rsa) that you would like to use to connect to GitHub, you can add your SSH key to the ssh-agent.

Tip: If you receive an error that ~/.ssh doesn't exist, don't worry! We'll create it when we generate a new SSH key.

Linux

  1. Open Terminal.

  2. Enter ls -al ~/.ssh to see if existing SSH keys are present:

    $ ls -al ~/.ssh
    # Lists the files in your .ssh directory, if they exist
  3. Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following:

    • id_rsa.pub
    • id_ecdsa.pub
    • id_ed25519.pub

If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key.

If you see an existing public and private key pair listed (for example id_rsa.pub and id_rsa) that you would like to use to connect to GitHub, you can add your SSH key to the ssh-agent.

生成新的SSH密钥

Windows

  1. Open Git Bash.

  2. Paste the text below, substituting in your GitHub email address.

    $ ssh-keygen -t rsa -b 4096 -C  "[email protected]"

    This creates a new ssh key, using the provided email as a label.

    > Generating public/private rsa key pair.
  3. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.

    > Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
  4. At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".

    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]

Linux

  1. 打开终端。

  2. 粘贴以下文本,替换为您的GitHub电子邮件地址。

    $ ssh-keygen -t rsa -b 4096 -C "[email protected]"

    使用提供的电子邮件作为标签,这将创建一个新的ssh密钥。

    > Generating public/private rsa key pair.
  3. 当提示您“输入要在其中保存密钥的文件”时,请按Enter。这接受默认文件位置。

    > Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
  4. 在提示符下,键入一个安全密码。有关更多信息,请参阅“使用SSH密钥密码短语”

    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]

将SSH密钥添加到ssh-agent

在将新的SSH密钥添加到ssh-agent来管理密钥之前,您应该已经检查了现有的SSH密钥生成了一个新的SSH密钥

  1. 在后台启动ssh-agent。

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
  2. 将SSH私钥添加到ssh-agent。如果您使用其他名称创建密钥,或者要添加具有其他名称的现有密钥,请使用私有密钥文件的名称替换命令中的id_rsa

    $ ssh-add ~/.ssh/id_rsa
  3. 将SSH密钥添加到您的GitHub帐户

打开gitbash终端

clip <~/.ssh/id_rsa.pub

然后在Key里复制粘贴,就会有key值出现

最后,在git终端下就可以copy我们的git仓库代码了

#git clone [email protected]:YourGitHub/YourProject.git
git clone [email protected]:CarryGitHub/Demo1.git

猜你喜欢

转载自www.cnblogs.com/CarryBlogs/p/12459466.html