Generating SSH keys

Generating SSH keys

SSH keys are a way to identify trusted computers, without involving passwords. The steps below will walk you through generating an SSH key and adding the public key to your GitHub account.

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.

Step 1: Check for SSH keys

First, we need to check for existing SSH keys on your computer. Open Git Bash and enter:

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

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 skip Step 2 and go straight to Step 3.

Tip: If you receive an error that ~/.ssh doesn‘t exist, don‘t worry! We‘ll create it in Step 2.

Step 2: Generate a new SSH key

  1. With Git Bash still open, copy and paste the text below. Make sure you substitute in your GitHub email address.

    ssh-keygen -t rsa -b 4096 -C "[email protected]"# Creates a new ssh key, using the provided email as a label# Generating public/private rsa key pair.
  2. We strongly suggest keeping the default settings as they are, so when you‘re prompted to "Enter a file in which to save the key", just press Enter to continue.
    # Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
  3. You‘ll be asked to enter a passphrase.
    # Enter passphrase (empty for no passphrase): [Type a passphrase]# Enter same passphrase again: [Type passphrase again]

    Tip: We strongly recommend a very good, secure passphrase. For more information, see "Working with SSH key passphrases".

  4. After you enter a passphrase, you‘ll be given the fingerprint, or id, of your SSH key. It will look something like this:
    # Your identification has been saved in /Users/you/.ssh/id_rsa.# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.# The key fingerprint is:# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]

Step 3: Add your key to the ssh-agent

To configure the ssh-agent program to use your 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 backgroundssh-agent -s# Agent pid 59566
    • If you are using another terminal prompt, such as msysgit, turn on ssh-agent:
      # start the ssh-agent in the backgroundeval $(ssh-agent -s)# Agent pid 59566
  2. Add your SSH key to the ssh-agent:
    ssh-add ~/.ssh/id_rsa

Tip: If you didn‘t generate a new SSH key in Step 2, and used an existing SSH key instead, you will need to replace id_rsain the above command with the name of your existing private key file.

Step 4: Add your SSH key to your account

To configure your GitHub account to use your SSH key:

Copy the SSH key to your clipboard. If your key is named id_dsa.pubid_ecdsa.pub orid_ed25519.pub, then change the filename below from id_rsa.pub to the one that matches your key:

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

Warning: It‘s important to copy the key exactly without adding newlines or whitespace.

Add the copied key to GitHub:

  1. In the top right corner of any page, click your profile photo, then click Settings.
  2. In the user settings sidebar, click SSH keys.
  3. Click Add SSH key.
  4. 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".
  5. Paste your key into the "Key" field.
  6. Click Add key.
  7. Confirm the action by entering your GitHub password.

Step 5: Test the connection

To make sure everything is working, you‘ll now try to SSH into GitHub. When you do this, you will be asked to authenticate this action using your password, which is the SSH key passphrase you created earlier.

  1. Open Git Bash and enter:

    ssh -T [email protected]# Attempts to ssh to GitHub
  2. You may see this warning:
    # The authenticity of host ‘github.com (207.97.227.239)‘ 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)?

    Verify 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.
  3. If the username in the message is yours, you‘ve successfully set up your SSH key!

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

    If you‘re switching from HTTPS to SSH, you‘ll now need to update your remote repository URLs. For more information, see Changing a remote‘s URL.

时间: 2024-10-30 20:33:04

Generating SSH keys的相关文章

Generating SSH Keys [Ubuntu Linux]

Generating SSH Keys We strongly recommend using an SSH connection when interacting with GitHub. SSH keys are a way to identify trusted computers, without involving passwords. The steps below will walk you through generating an SSH key and then adding

Generating SSH Keys on windows

two ways here I provide: use openSSH command line on git bash(such as msysgit bash) ls -al ~/.ssh ssh-keygen -t rsa -C "[email protected]" eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa clip < ~/.ssh/id_rsa.pub ssh -T [email protected

Github 配置SSH keys教程

不知道什么原因,CSDN博客保存的时候会丢失图片和格式,请可以戳这里到我有道云笔记分享 今天特地把Github上的教程Github Generating SSH keys翻译成中文(并非全文翻译),因为自己的水平有限,有错误还请指出. SSH key 是为了确认你是项目的管理者或拥有者,然后可以不使用密码使用git.当然使用github的时候要用SSH链接,用https的话就无所谓了.  https可以clone任何人的project,但SSH只能clone属于你的,你必须是这个项目的拥有者.

SSH keys Generate

An SSH key allows you to establish a secure connection between your computer and GitLab. Before generating an SSH key, check if your system already has one by running cat ~/.ssh/id_rsa.pub. If you see a long string starting with ssh-rsa or ssh-dsa, y

git SSH keys

An SSH key allows you to establish a secure connection between your computer and GitLab. Before generating an SSH key in your shell, check if your system already has one by running the following command: Windows Command Line: type %userprofile%\.ssh\

Github for Mac - SSH keys

http://blog.csdn.net/britainwei/article/details/44591297 http://www.jianshu.com/p/31cbbbc5f9fa/ 准备: (1)注册Github账号 (2)下载Github for Mac客户端并登录 这个时候可以从Github上Clone in Desktop ,把工程clone到电脑上,但是不能够把新建的工程上传到Github.还需要配置一些东西. 我们用Github的时候,常用的功能:下载,上传,修改,分支,多人

git ssh keys生成步骤

1.在github上面注册... 2.生成ssh密钥生成过程 1).查看是否已经有了ssh密钥: cd ~/.ssh 2).生成密钥 $ ssh-keygen -t rsa -C "[email protected]"  (注册github的邮箱账号) 回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key.为了验证是否成功,在git bash下输入: $ ssh -T [email protected]

为github帐号添加SSH keys(Linux和Windows)

文章转自:https://blog.cofface.com/archives/406.html/2 一.Linux增加ssh keys方法: 使用git clone命令从github上同步github上的代码库时,如果使用SSH链接(如我自己的cofface_recovery项目:[email protected]:cofface/cofface_recovery.git),而你的SSH key没有添加到github帐号设置中,系统会报下面的错误:Permission denied (publi

Git 进阶指南(git ssh keys / reset / rebase / alias / submodule )

在掌握了基础的 Git 使用 之后,可能会遇到一些常见的问题.以下是猫哥筛选总结的部分常见问题,分享给各位朋友,掌握了这些问题的中的要点之后,git 进阶也就完成了,它包含以下部分: 如何修改 origin 仓库信息 如何配置 git ssh keys 如何撤销修改 遇到冲突了怎么解决 git stash / alias / submodule 的使用问题等 问:如何修改 origin 仓库信息? 1.添加 origin 仓库信息 git remote add origin <git仓库地址>