首页
找靠谱产品
找解决方案
找靠谱公司
找案例
找对的人
专家智库
悬赏任务
SAAS
ToB门户
了解全球最新的ToB事件
论坛
潜水/灌水快乐,沉淀知识,认识更多同行。
ToB圈子
加入IT圈,遇到更多同好之人。
微博
Follow
记录
Doing
博客
Blog
文库
业界最专业的IT文库,上传资料也可以赚钱
下载
分享
Share
排行榜
Ranklist
相册
Album
应用中心
qidao123.com ToB IT社区-企服评测·应用市场
»
论坛
›
软件与程序人生
›
DevOps与敏捷开发
›
git配置ssh key
返回列表
发新帖
git配置ssh key
[复制链接]
发表于 2024-10-23 16:52:25
|
显示全部楼层
|
阅读模式
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要
登录
才可以下载或查看,没有账号?
立即注册
×
一、天生ssh公钥和私钥对
打开
终端
,输入下令,-C 后是git邮箱,在
Enter file in which to save the key (/home/my/.ssh/id_rsa):
后可以输入公钥和私钥对保存路径及文件名,默认是
/home/my/.ssh/id_rsa
,别的的全部按回车即可。(公钥和私钥对保存路径及文件名不是默认的必要
配置
config)
my@ubuntu:~$ ssh-keygen -t rsa -C '
[email protected]
'
Generating public/private rsa key pair.
Enter file in which to save the key (/home/my/.ssh/id_rsa): /home/my/.ssh/id_rsa_ldc
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/my/.ssh/id_rsa_ldc
Your public key has been saved in /home/my/.ssh/id_rsa_ldc.pub
The key fing
erp
rint is:
SHA256:O2EBiWUW+VyztfbRIC7wMN1s0sNHJu6heCVdL+X86bg
[email protected]
The key's randomart image is:
+---[RSA 3072]----+
| o*+ . =..+ .|
| .oo.+ =oX+o= |
| o.*.B==.o+|
| oo+=+...+|
| S oo.. o.|
| . + + |
| o . . |
| . . |
| E |
+----[SHA256]-----+
my@ubuntu:~/.ssh$
复制
代码
二、添加SSH密钥
1. 打开~/.ssh/id_rsa.pub文件(~表示用户目次,好比我的windows就是C:\Users\Administrator),复制其中的内容。
2. 打开见面,登录git,找到 用户设置——>SSH密钥,如下图所示。
至此,假如天生的公钥和私钥对是默认路径,便可以通过 git clone ssh://
[email protected]
/myproject.git来访问了。
三、config
当天生的公钥和私钥对不是默认路径或者你必要多个git
服务器
时,必要
配置
config文件。打开文件。
vim ~/.ssh/config
复制
代码
在文件中输入以下内容
# gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_id-rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id-rsa
# gitlab.my.com
Host gitlab.my.com
HostName 192.168.10.183
Port 9022
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_my
#
配置
文件参数
# Host : Host可以看作是一个你要识别的模式,对识别的模式,进行配置对应的的主机名和ssh文件
# HostName : 要登录主机的主机名
# User : 登录名
# IdentityFile : 指明上面User对应的identityFile路径
# Port : 端口
复制
代码
对于gitlab.my.com中由于主机名是ip,必要配置hosts,打开hosts文件
sudo vim etc/hosts
复制代码
添加一行
192.168.10.183 gitlab.my.com
复制代码
访问时使用:git clone ssh://
[email protected]
:9022/myproject.git
四、验证
ssh-keygen -R 172.22.195.183
ssh -p 8022
[email protected]
example:
cch@ldc:~/work/notes$ ssh
[email protected]
Hi 奋斗的cch(@struggling-cch)! You've successfully authenticated, but GITEE.COM does not provide shell access.
Connection to gitee.com closed.
复制代码
回复
使用道具
举报
返回列表
浏览过的版块
运维.售后
.Net
Java
SAAS
IT职场那些事
物联网
公有云
分布式数据库
数据仓库与分析
北冰洋以北
+ 我要发帖
登录后关闭弹窗
登录参与点评抽奖 加入IT实名职场社区
去登录
微信订阅号
微信服务号
微信客服(加群)
H5
小程序
快速回复
返回顶部
返回列表