美文网首页
一台终端-多个ssh-key配置

一台终端-多个ssh-key配置

作者: ricefun | 来源:发表于2020-03-04 17:52 被阅读0次

1、生成SSH-Key

$ ssh-keygen -t rsa -C "youremail@xxx.com" -f ~/.ssh/id_rsa_github
$ ssh-keygen -t rsa -C "youremail@xxx.com" -f ~/.ssh/id_rsa_gitlab

2、查看公钥

$ cat ~/.ssh/id_rsa_github.pub
$ cat ~/.ssh/id_rsa_gitlab.pub

3、将公钥内容复制粘贴至gitlab/github SSH公钥

4、添加私钥

$ ssh-add ~/.ssh/id_rsa_gitlab
$ ssh-add ~/.ssh/id_rsa_github

5、添加配置文件

//进入ssh目录
$  cd ~/.ssh
//新建config文件
$ touch config

6、编辑config文件

//打开ssh文件
$  open ~/.ssh

打开config文件进行如下编辑

# gitlab
Host gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitlab
# github
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github
#用于自动添加ssh
Host *
   UseKeychain yes
   AddKeysToAgent yes
   IdentityFile ~/.ssh/id_rsa_gitlab
   IdentityFile ~/.ssh/id_rsa_github

# 配置文件参数
# Host : Host可以看作是一个你要识别的模式,对识别的模式,进行配置对应的的主机名和ssh文件
# HostName : 要登录主机的主机名
# IdentityFile : 指明上面User对应的identityFile路径

编辑好后 command + s保存下,这样就OK了

7、测试

$ ssh -T git@github.com

第一次链接会出现提示Are you sure you want to continue connecting (yes/no)? 输入yes回车。
提示下面的就代表成功了!
Hi riceFun! You've successfully authenticated, but GitHub does not provide shell access.

相关文章

  • Git配置多个SSH-Key & python中git的使用

    一、配置多个SSH-Key 当前电脑已设置过了一个ssh-key,终端查看已配置的SSH-Key文件 cd ~/....

  • 一台终端-多个ssh-key配置

    1、生成SSH-Key 2、查看公钥 3、将公钥内容复制粘贴至gitlab/github SSH公钥 4、添加私钥...

  • Git配置多个SSH-KEY

    git可以配置多个ssh-key。 生成多个ssh-key命令 添加私钥

  • git总结

    GitHub创建远程仓库 配置多个SSH-key 当公司gitlab和自己的github都要配置ssh-key时,...

  • 一台电脑配置多个SSH-Key

    背景:因为我们github与公司的gitlab的账号一般不是同一个,所以需要在一台电脑配置多个SSH-Key 1....

  • git配置多个SSH-Key

    我们在日常工作中会遇到同一台服务器部署多个放在github上的应用,这样我们就需要配置不同的ssh-key对应不同...

  • (SSH) GitHub、GitLab、Gitee添加SSH认证

    一)生成SSH-key 打开终端,执行如下指令: 二)配置config文件(可选步骤) cd ~/.ssh tou...

  • 配置多个SSH-Key

    为了安全性,个人的github和公司的gitlab需要配置不同的SSH-Key。具体如下: 切换到系统的SSH目录...

  • Github使用笔记

    一、配置Github环境 安装Git 配置ssh-key 检查ssh-key的设置 生成新ssh-key 添加ss...

  • mac管理多个ssh key

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

网友评论

      本文标题:一台终端-多个ssh-key配置

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