场景
经常使用git工具后者登录服务器的小伙伴肯定都会配置ssh免登录,这样技能提升效率,又安全,本文就讲一下配置ssh免登录相关的工作。
本文以Mac为例,Windows环境大同小异
相关文件
ssh的配置,存服务器内存条可以用在台式机上吗储在测试你的自卑程度用户目录的.ssh隐藏文件夹下cd ~/.ssh && ls -a
查看目录会服务器怎么搭建看到几个文件
- id_rsa
- id_rsa_pub
- config(如果没有,请手动创建)
- known_hostsgitlab是干什么用的(如果没有,请手动创建)
id_rsa是私钥,始终存储在本机设备上, id_ras_pub是和私钥对应的公钥,通常配置到远程仓库或者远程服务器上,github和gigitlab登录tlab等测试你的自卑程度在设置中都可以找到ssh配置方法
config是用来管理多个公私钥对与不同服务对gitlab拉取代码到本地配git命令置关系,长下面这个样子
Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
known_hosts里面记录的是每次通过ssh链接到远程服务或gigitlab使用教程t服务时,使用的公钥信息,下次成功连接时就会写入公钥信息,当远程的公钥发生改变,和known_hosts文件中不匹配就会提示WARNING: REMOTE HOST IDENTIFICATION HA测试S CHANGED!
设置ssh免登录
生成测试你适合学心理学吗秘钥对
ssh-keygen -t rsa -C "YOUR_EMAIL@YOU安全REMAIL.COM" -f ~/.ssh/gitee
-t 指定密钥类型,默认是 rsa ,可以省略。 -C 设置注释文字,比如邮箱。 -f 指定密钥文件存储文件名。
名字默认为id_rsa和id_rsa.pub 这里强烈建议通过-f参数,修改为对应的平台,例如github,gitlab,gitee等
执行后一直按回车键确认即可,最后出现下面内容即成功
Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/peakj/code_space/mess/test Your public key has been saved in /Users/peakj/code_space/mess/test.pub The key fingerprint is: SHA256:OuHLjibJ7GQ35n4gY8rpANSEWknCZetjKSCz8S4OwCk YOUR_EMAIL@YOUREMAIL.COM The key's randomart image is: +---[RSA 3072]----+ |o.+= | | +* . | |*o o | |*=o . | |E+.= . S | |+.* o. o | |===++.+ | |=*=+.+.o | |.+.++o+ | +----[SHA256]-----+
然后执行cat gitee.pub
打印出公钥内容,复制gitlab中文官网粘贴到对应的平台即可
配置域名和私钥对应关系
# gitee Host gitee.com HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitee
Host #域名,可以是IP地址
HostName #域名名称
PreferredAuthegiticomfort是什么轮胎ntications publickey #安全期计算器默认值,不需要修改
IdentityFi测试英文legithub中文官网网页 ~/.ssh/gitee #匹配本地的私钥文件
我的配置:
# github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa # gitlab Host git.100tal.com HostName git.100tal.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitlab_rsa # gitee Host gitee.com HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitee
ssh目录下的文件:
├── config ├── gitee ├── gitee.pub ├── gitlab_rsa ├── gitlab_rsa.pub ├── id_rsa ├── id_rsa.pub ├── known_hosts
测试ssh(以gitee为例)
ssh -T git@gitee.com
如果出现Hi USERNAME! You've successfully authenticated, but github does not provide shell access.
说明配置成功
如果出现Per安全missgitlab官网ion denied (publickey)
说明权限安全工程师有问题,检查config文件是否有名称或者路径错误,或者公钥是否正确配置到远端服务
评论(0)