首页 技术 正文
技术 2022年11月22日
0 收藏 608 点赞 4,381 浏览 5766 个字

从github上获取的,自己整理了下,以备后用。

Generating an SSH key

SSH keys are a way to identify trusted computers without involving passwords. You can generate an SSH key and add the public key to your GitHub account by following the procedures outlined in this section.

We recommend that you regularly review your SSH keys list and revoke any that haven’t been used in a while.

Tip: If you have GitHub for Windows installed, you can use it to clone repositories and not deal with SSH keys. It also comes with the Git Bash tool, which is the preferred way of running git commands on Windows.

Checking for existing SSH keys

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

Generating a new SSH key and adding it to the ssh-agent

After you’ve checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.

Adding a new SSH key to your GitHub account

To configure your GitHub account to use your new (or existing) SSH key, you’ll also need to add it to your GitHub account.

Testing your SSH connection

After you’ve set up your SSH key and added it to your GitHub account, you can test your connection.

Checking for existing SSH keys

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

  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_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub
  • id_rsa.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.

Generating a new SSH key and adding it to the ssh-agent

After you’ve checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.

Generating a new SSH key

  1. Open Git Bash.

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

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    # 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 (/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]

Adding your SSH key to the ssh-agent

Before adding a new SSH key to the ssh-agent, you should have checked for existing SSH keys and generated a new SSH key.

If you have GitHub for Windows installed, you can use it to clone repositories and not deal with SSH keys. It also comes with the Git Bash tool, which is the preferred way of running git commands on Windows.

  1. Ensure ssh-agent is enabled:

    • If you are using Git Bash, turn on ssh-agent:

      # start the ssh-agent in the background
      eval "$(ssh-agent -s)"
      Agent pid 59566
    • If you are using another terminal prompt, such as Git for Windows, turn on ssh-agent:

      # start the ssh-agent in the background
      eval $(ssh-agent -s)
      Agent pid 59566
  2. Add your SSH key to the ssh-agent. If you used an existing SSH key rather than generating a new SSH key, you’ll need to replace id_rsa in the command with the name of your existing private key file.

    $ ssh-add ~/.ssh/id_rsa
  3. Add the SSH key to your GitHub account.

Adding a new SSH key to your GitHub account

To configure your GitHub account to use your new (or existing) SSH key, you’ll also need to add it to your GitHub account.

Before adding a new SSH key to your GitHub account, you should have:

  1. Copy the SSH key to your clipboard.

    If your SSH key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace.

    $ clip < ~/.ssh/id_rsa.pub
    # Copies the contents of the id_rsa.pub file to your clipboard

    Tip: If clip isn’t working, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

  2. github免输用户名/密码SSH登录的配置In the top right corner of any page, click your profile photo, then click Settings.

  3. github免输用户名/密码SSH登录的配置In the user settings sidebar, click SSH and GPG keys.

  4. github免输用户名/密码SSH登录的配置Click New SSH key or Add SSH key.

  5. In the “Title” field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key “Personal MacBook Air”.
  6. github免输用户名/密码SSH登录的配置Paste your key into the “Key” field.
  7. github免输用户名/密码SSH登录的配置Click Add SSH key.
  8. github免输用户名/密码SSH登录的配置If prompted, confirm your GitHub password.

 

Testing your SSH connection

After you’ve set up your SSH key and added it to your GitHub account, you can test your connection.

Before testing your SSH connection, you should have:

When you test your connection, you’ll need to authenticate this action using your password, which is the SSH key passphrase you created earlier. For more information on working with SSH key passphrases, see “Working with SSH key passphrases”.

  1. Open Git Bash.

  2. Enter the following:

    ssh -T git@github.com
    # Attempts to ssh to GitHub

    You may see one of these warnings:

    The authenticity of host 'github.com (192.30.252.1)' can't be established.
    RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
    Are you sure you want to continue connecting (yes/no)?
    The authenticity of host 'github.com (192.30.252.1)' can't be established.
    RSA key fingerprint is nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
    Are you sure you want to continue connecting (yes/no)?

    Note: The example above lists the GitHub IP address as 192.30.252.1. When pinging GitHub, you may see a range of IP addresses. For more information, see “What IP addresses does GitHub use that I should whitelist?”

  3. Verify that the fingerprint in the message you see matches the following message, then type yes:

    Hi username! You've successfully authenticated, but GitHub does not
    provide shell access.
  4. Verify that the resulting message contains your username. If you see a message that contains “access denied,” see “Error: Permission denied (publickey)”.

    If you receive a message about “access denied,” you can read these instructions for diagnosing the issue.

  5. If you’re switching from HTTPS to SSH, you’ll need to update your remote repository URLs.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918