SSH key

作者: JXeddy | 来源:发表于2018-05-16 02:37 被阅读0次

使用ssh key

  1. 检查SSH keys是否存在
    输入下面的命令,如果有文件id_rsa.pub 或 id_dsa.pub,则直接进入步骤3将SSH key添加到GitHub中,否则进入第二步生成SSH key

ls -al ~/.ssh

Lists the files in your .ssh directory, if they exist

like ls: /Users/eddy/.ssh: No such file or directory 则没有ssh key

  1. 生成新的ssh key
    第一步:生成public/private rsa key pair
    在命令行中输入ssh-keygen -t rsa -C "your_email@example.com"

或者ssh-keygen -t rsa

默认会在相应路径下(/your_home_path)生成id_rsa和id_rsa.pub两个文件,如下面代码所示

ssh-keygen -t rsa -C "your_email@example.com"# Creates a new ssh key using the provided emailGenerating public/private rsa key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_rsa):

第二步:输入passphrase(本步骤可以跳过)

设置passphrase后,进行版本控制时,每次与GitHub通信都会要求输入passphrase,以避免某些“失误”

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

Enter same passphrase again: [Type passphrase again]

第三步:将新生成的key添加到ssh-agent中:

start the ssh-agent in the backgroundeval "$(ssh-agent -s)"Agent pid 59566ssh-add ~/.ssh/id_rsa

测试:
eddytekiMBP:~ eddy$ eval "$(ssh-agent -s)"
Agent pid 1871
eddytekiMBP:~ eddy$ ssh-add ~/.ssh/id_rsa
Identity added: /Users/eddy/.ssh/id_rsa (/Users/eddy/.ssh/id_rsa)
eddytekiMBP:~ eddy$

  1. 将ssh key添加到GitHub中
    用自己喜欢的文本编辑器打开id_rsa.pub文件,里面的信息即为SSH key,将这些信息复制到GitHub的Add SSH key页面即可

不同的操作系统,均有一些命令,直接将SSH key从文件拷贝到粘贴板中,如下:

mac

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

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

sudo apt-get install xclip# Downloads and installs xclip. If you don't have apt-get, you might need to use another installer (like yum)xclip -sel clip < ~/.ssh/id_rsa.pub# Copies the contents of the id_rsa.pub file to your clipboard

ssh-keygen -f "~/.ssh/known_hosts" -R 192.168.1.254

相关文章

  • SSH Key的创建与查看

    查看本地是否存在SSH Key 生成新的SSH Key 生成并添加SSH Key 查看SSH Ket

  • Git 简明教程

    SSH 进入 SSH 文件夹 生成 SSH Key 输入 SSH Key 名字 和 Key(此步骤可忽略) 显示 ...

  • 查看/创建ssh key

    1、查看SSH Key: cd ~/.sshcat id_rsa.pub 2、创建SSH Key: ssh-key...

  • git基本操作

    设置SSH key 1、Settings——SSH and GPG keys——New SSH key2、需要输入...

  • SSH key的生成及使用

    SSH key的生成及使用 SSH key生成及其使用 一、检查是否已经存在ssh key 通常sshkey会默认...

  • gitlab--ssh key配置

    生成&配置ssh key 因为之前已经给github配置了ssh key,这里直接输出已经生成的ssh key 生...

  • Panda8zDiary--2018-07-24

    Generating a new SSH key pair To generate a new SSH key p...

  • ssh-keygen

    ssh-keygen 生成 key,默认在位置 .ssh ssh-keygen -C 'vultr' 将 key ...

  • Github的SSH KEY配置

    生成SSH Key 生成SSH KEY: ssh-keygen -t rsa -C "your_email@exa...

  • mac管理多个ssh key

    生成SSH-Key (1)打开终端,进入到.ssh文件夹内 (2)生成ssh-key 在生成ssh-key时,会让...

网友评论

      本文标题:SSH key

      本文链接:https://www.haomeiwen.com/subject/jxuudftx.html