如何使用git终端
检查是否存在SSH密码
Before you generate an SSH key, you can check to see if you have any existing SSH keys.
Windows
-
Open Git Bash.
-
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
-
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
-
Open Terminal.
-
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
-
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
-
Open Git Bash.
-
Paste the text below, substituting in your GitHub email address.
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This creates a new ssh key, using the provided email as a label.
> Generating public/private rsa key pair.
-
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]
-
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
-
打开终端。
-
粘贴以下文本,替换为您的GitHub电子邮件地址。
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
使用提供的电子邮件作为标签,这将创建一个新的ssh密钥。
> Generating public/private rsa key pair.
-
当提示您“输入要在其中保存密钥的文件”时,请按Enter。这接受默认文件位置。
> Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
-
在提示符下,键入一个安全密码。有关更多信息,请参阅“使用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密钥。
-
在后台启动ssh-agent。
$ eval "$(ssh-agent -s)" > Agent pid 59566
-
将SSH私钥添加到ssh-agent。如果您使用其他名称创建密钥,或者要添加具有其他名称的现有密钥,请使用私有密钥文件的名称替换命令中的id_rsa。
$ ssh-add ~/.ssh/id_rsa
打开gitbash终端
clip <~/.ssh/id_rsa.pub
然后在Key里复制粘贴,就会有key值出现
最后,在git终端下就可以copy我们的git仓库代码了
#git clone git@github.com:YourGitHub/YourProject.git
git clone git@github.com:CarryGitHub/Demo1.git