设备添加ssh 给git仓库

时间:2021-07-26
本文章向大家介绍设备添加ssh 给git仓库,主要包括设备添加ssh 给git仓库使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Generating a new SSH key pair

Before creating an SSH key pair, make sure to understand the
different types of keys.
To create a new SSH key pair:

  1. Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.
  2. Generate a new ED25519 SSH key pair:
    ssh-keygen -t ed25519 -C "email@example.com"
    Or, if you want to use RSA:
    ssh-keygen -t rsa -b 4096 -C "email@example.com"
    The -C flag adds a comment in the key in case you have multiple of them
    and want to tell which is which. It is optional.
  3. Next, you will be prompted to input a file path to save your SSH key pair to.
    If you don't already have an SSH key pair and aren't generating a deploy key,
    use the suggested path by pressing
    Enter. Using the suggested path will normally allow your SSH client
    to automatically use the SSH key pair with no additional configuration.
    If you already have an SSH key pair with the suggested file path, you will need
    to input a new file path and declare what host
    this SSH key pair will be used for in your ~/.ssh/config file.
  4. Once the path is decided, you will be prompted to input a password to
    secure your new SSH key pair. It's a best practice to use a password,
    but it's not required and you can skip creating it by pressing
    Enter twice.
    If, in any case, you want to add or change the password of your SSH key pair,
    you can use the -p flag:
    ssh-keygen -p -f <keyname>

Adding an SSH key to your GitLab account

  1. Copy your public SSH key to the clipboard by using one of the commands below
    depending on your Operating System:
    macOS:
    pbcopy < ~/.ssh/id_ed25519.pub
    WSL / GNU/Linux (requires the xclip package):
    xclip -sel clip < ~/.ssh/id_ed25519.pub
    Git Bash on Windows:
    cat ~/.ssh/id_ed25519.pub | clip
    You can also open the key in a graphical editor and copy it from there,
    but be careful not to accidentally change anything.
    NOTE: Note:
    If you opted to create an RSA key, the name might differ.

  2. Add your public SSH key to your GitLab account by:

1.Clicking your avatar in the upper right corner and selecting Settings.
2.Navigating to SSH Keys and pasting your public key in the Key field. If you:

  • Created the key with a comment, this will appear in the Title field.
  • Created the key without a comment, give your key an identifiable title like Work Laptop or Home Workstation.
    3.Click the Add key button.

NOTE: Note:
If you manually copied your public SSH key make sure you copied the entire
key starting with ssh-ed25519 (or ssh-rsa) and ending with your email.

原文地址:https://www.cnblogs.com/Acheng20/p/15060855.html