SSH不对称密钥自动登入服务器
SSH不对称密钥自动登入服务器
1、先在自己的电脑上创建密钥对
ssh-keygen -t rsa
Windows下生成SSH密钥
$ ssh-keygen -t rsa -C "youremail@example.com"
这时可以在主机A上看到生成的秘钥~/.ssh/idrsa 和公钥 ~/.ssh/ idrsa.pub
2、把公钥放传输到服务器上
第一步是以安装Ubuntu 22.04时创建的用户名和密码登入服务器。
我们用最优秀的跨平台SSH客户端,在windows store里直接下载
新建一个Host,配置如下:
新的服务器,用这条命令给root账户设置密码
sudo passwd root
然后切换到root账户登入
su root
去修改root用户的SSH公钥配置
cd /root
cd .ssh
vi authorized_keys
把自己的公钥贴到上述文件,保存后退出vi编辑器
上述一堆命令的效果图如下:
3、使用客户端工具免密密码登入
上述演示基于从ubuntu.com官方网站下载的iso映像,全新安装的Ubuntu 22.04服务器。如果不是这样的服务器环境,可能您还需要继续往下看:
4、修改ssh服务配置文件
sudo vi /etc/ssh/sshd_config
- 要检查的几个选项:
PermitRootLogin yes #允许root登录
PermitEmptyPasswords yes #允许空密码登录
PasswordAuthentication yes # 设置是否使用口令验证。
5、重新启动SSH服务
service sshd start 开启ssh服务
service sshd stop 停止ssh服务
service sshd restart 重启ssh服务
6、SSH命令的两个重要开关
1)-i,用途是指定私钥的文件路径
2)-vT,用途是输出详细的信息
PS C:\Users\David> ssh -i X:\gitlab-runner\ssh\id_rsa great@proget.abcdefg.cn -vT
OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to proget.abcdefg.cn [47.106.133.5] port 22.
debug1: Connection established.
debug1: identity file X:\\gitlab-runner\\ssh\\id_rsa type 0
debug1: identity file X:\\gitlab-runner\\ssh\\id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.1
debug1: compat_banner: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to proget.abcdefg.cn:22 as 'great'
debug1: load_hostkeys: fopen C:\\Users\\David/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:g+AgPHqhDZhgIE0yiuMlkIEQfefGlSSO4jeWM8Ekd5A
debug1: load_hostkeys: fopen C:\\Users\\David/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'proget.abcdefg.cn' is known and matches the ED25519 host key.
debug1: Found key in C:\\Users\\David/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: X:\\gitlab-runner\\ssh\\id_rsa RSA SHA256:6QNUIUX5zptZfoIHVWBJW8slxrzUsCwMojRe4vo3Fnk explicitdebug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com>
debug1: kex_input_ext_info: publickey-hostbound@openssh.com (unrecognised)
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: X:\\gitlab-runner\\ssh\\id_rsa RSA SHA256:6QNUIUX5zptZfoIHVWBJW8slxrzUsCwMojRe4vo3Fnk explicit
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
great@proget.abcdefg.cn's password:
PS C:\Users\David>
7、远程服务器.ssh权限问题
远程服务器~/.ssh文件夹及其文件权限不对,包括
1、~./ssh/authorized_keys文件权限
2、~/.ssh文件夹权限
3、~/.ssh文件夹所有权
Solution
通过其它方式登录到远程服务器,如果是阿里云则可以在网页中通过验证之后打开一个终端,然后进行如下操作
7.1、更改文件所有权
$ chown -R your_user:your_group ~/.ssh
//我用root登录,your_user是root
7.2、更改.ssh文件夹权限
$ chmod 700 ~/.ssh
7.3、更改.ssh/authorized_keys文件权限
$ chmod 600 ~/.ssh/authorized_keys
第7段是拷贝自这个作者:
作者:delta1037
链接:https://www.jianshu.com/p/14027e35b900
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
暂时总结这么多。
SSH不对称密钥自动登入服务器的更多相关文章
- 如何通过linux ssh远程linux不用输入密码登入
如何通过一台linux ssh远程其他linux服务器时,不要输入密码,可以自动登入.提高远程效率,不用记忆各台服务器的密码. 工具/原料 ssh,ssh-keygen,scp 方法/步骤 首 ...
- 网络爬虫之requests模块的使用+Github自动登入认证
本篇博客将带领大家梳理爬虫中的requests模块,并结合Github的自动登入验证具体讲解requests模块的参数. 一.引入: 我们先来看如下的例子,初步体验下requests模块的使用: ...
- Ubuntu获取root 权限,开机自动登入root
新机器获取root权限,只需要给root 增加密码: sudo passwd root 修改开机自动登入: #sudo gedit /etc/lightdm/lightdm.conf 修改参数: au ...
- python selenium 多账户自动登入163邮箱
pycharm一些快捷键: ' ctrl ' +' / ' :注释 ' Tab ' :同时缩进 ' shift ' +' Tab ' :左移 一次缩进 本文webinfo.txt路径:C:\Pytho ...
- 使用ssh公钥密钥自动登陆linux服务器
转自:http://7056824.blog.51cto.com/69854/403669 作为一名 linux 管理员,在多台 Linux 服务器上登陆进行远程操作是每天工作的一部分.但随着服务器的 ...
- [zz] 使用ssh公钥密钥自动登陆linux服务器
目录 .生成密匙对 .拷贝公匙到远程机 .启动登陆代理 这种方法处理后每次需要运行命令:ssh-add ~/.ssh/id_dsa 作为一名 linux 管理员,在多台 Linux 服务器上登陆进行远 ...
- ssh自动登入
公司的服务器在国外,所以测试的查看日志的时候需要测试机,然后继续ssh 非常不方便,所以编写一个简单的ssh登入脚本 #!/usr/bin/expectset timeout 3spawn ssh n ...
- ssh 使用密钥无法登入Linux系统
今天测试密钥登入linux系统时 出现如下问题: root@compute01:~# ssh alicxxx@xxx.com -p -i alickicxxxxxxx.key @@@@@@@@@@@@ ...
- [整理]配置SSH密钥自动登录远程服务器
原理: 公钥私钥匹配通过验证,允许访问服务器. 简单步骤: 1.在本地创建一对密钥 2.将公钥传到需要访问的服务器上 3.将公钥放入服务器的authorized_keys,确保访问时能通过验证 4.本 ...
- ssh连接远程主机免密登入
核心思想: 1.本地主机生成公钥私钥,私钥自己存着,公钥传到远程主机.ssh文件夹下authorized_keys文件(默认是这个,用追加的方式) 2.本地连接远程主机,公私钥对上就可以免密登入了. ...
随机推荐
- [转帖]Unixbench服务器综合性能测试方法及工具下载
UnixBench是一款开源的测试 unix 系统基本性能的工具,是比较通用的测试VPS性能的工具. UnixBench会执行一系列的测试,包括2D和3D图形系统的性能衡量,测试的结果不仅仅只是CPU ...
- Opentelemetry Collector的配置和使用
Collector的配置和使用 目录 Collector的配置和使用 Collector配置 Receivers Processors Exporters Service Extensions 使用环 ...
- 京东金融APP-新交互技术“虚拟数字人”赋能世界杯主题营销
作者:平台研发部,智能服务与产品部 距离加文·伍德提出web3.0已经过去8年时间,这8年加文·伍德创建的以太坊大放异彩,同时由web3.0引出的数字人.元宇宙也生根发芽,茁壮成长,带来了非凡的用户体 ...
- DPText-DETR: 基于动态点query的场景文本检测,更高更快更鲁棒 | 京东探索研究院
针对场景文本检测任务,近期基于DEtection TRansformer (DETR) 框架预测控制点的研究工作较为活跃.在基于DETR的检测器中,query的构建方式至关重要,现有方法中较为粗糙的位 ...
- Vue.use和install之间的关系
创建一个plugins.js文件 跟main.js同级下,创建一个plugins.js文件 export default { // install是vue给我们提供的.它会自动去执行install. ...
- dwm 美化
在之前的博客中,我们将arch linux这个系统进行了一些美化,当然也是仅仅做到能看这个地步,要说跟网上其他那些惊艳的特效对比,肯定是不如的.但是我一直秉持一个观点,美化应该适可而止,只要不是丑的你 ...
- 携程Java三面面经,已拿 offer!!
分享一位读者投稿的携程校招 Java 岗位的面经. 下面是正文. 个人背景:双非本,机械专业转码. 携程在正式面试之前,会有一个性格测试(40分钟).性格测试之后,大概过一周进行笔试.笔试之后,会邮件 ...
- SpringCloud-Gateway搭建保姆级教程
一.网关介绍 1.什么是网关? 使⽤服务⽹关作为接⼝服务的统⼀代理,前端通过⽹关完成服务的统⼀调⽤ 2.⽹关可以⼲什么? 路由:接⼝服务的统⼀代理,实现前端对接⼝服务的统⼀访问 过滤:对⽤户请求进⾏拦 ...
- PHP截取文章内容
<?php /** * 实现中文字串截取无乱码的方法. */ function getSubstr($string, $start, $length) { if (mb_strlen($stri ...
- 索引构建磁盘IO太高,巧用tmpfs让内存来帮忙
在文本索引构建这种需要大量占用磁盘IO的任务,如果正巧你的内存还有点余粮,是否可以先索引存储到内存,然后再顺序写入到磁盘呢?,需要大量占用磁盘IO,如果正巧你的内存还有点余粮,是否可以先索引存储到内存 ...