侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Linux配置远程SSH无密码登录

linux  /  管理员 发布于 5年前   95

本文实例为大家分享了jaLinux配置远程SSH无密码登录的方法,供大家参考,具体内容如下

系统:CentOS 6.8
主机1:192.168.0.177
主机2:192.168.0.178
工具介绍:
ssh-keygen:创建公钥和密钥
ssh-copy-id:把生成的公钥复制到192.168.0.178主机上的authorized_keys文件上,
ssh-copy-id也会给远程主机的用户主目录(/home)和/root/.ssh和/root/.ssh/authorized_key设置合适的权限

1)创建公钥和密钥

[root@test ~]# ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:79:a9:66:cd:1a:a5:7c:82:80:c3:06:ec:44:13:b9:7a root@testThe key's randomart image is:+--[ RSA 2048]----+| +o ||o.. ||.o. ||o+ . . . ||..= . S + ||..E. . o B || . . O + || o = || . |+-----------------+

[root@test ~]#

2)拷贝公钥到远程主机

[root@test ~]# ls .ssh/authorized_keys id_rsa id_rsa.pub[root@test ~]#[root@test ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected] authenticity of host '192.168.0.178 (192.168.0.178)' can't be established.RSA key fingerprint is 53:bd:d7:e6:27:96:f3:70:f1:4b:4d:35:a4:38:1d:69.Are you sure you want to continue connecting (yes/no)? YESWarning: Permanently added '192.168.0.178' (RSA) to the list of known [email protected]'s password:Now try logging into the machine, with "ssh '[email protected]'", and check in:.ssh/authorized_keysto make sure we haven't added extra keys that you weren't expecting.[root@test ~]#

3)测试远程连接

[root@test ~]# ip addr show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWNlink/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:7e:1f:f6 brd ff:ff:ff:ff:ff:ffinet 192.168.0.177/24 brd 192.168.0.255 scope global eth0inet6 fe80::20c:29ff:fe7e:1ff6/64 scope linkvalid_lft forever preferred_lft forever[root@test ~]#[root@test ~]# ssh 192.168.0.178Last login: Sat Sep 24 14:00:49 2016 from 192.168.0.103[root@test ~]#ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWNlink/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:36:93:06 brd ff:ff:ff:ff:ff:ffinet 192.168.0.178/24 brd 192.168.0.255 scope global eth0inet6 fe80::20c:29ff:fe36:9306/64 scope linkvalid_lft forever preferred_lft forever

查看192.168.0.177生成的authorized_keys

[root@test .ssh]# cat authorized_keysssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA+I6LXDE5DvSmQJcX98FpzScXoGpJ6fD47yXzp/tp/HTpOTQgNbiTjH6s6yNMsd5LQlBED8a5CTx5wKm+H7rT0po2xD+AZcF69js+4SwO8/xFwHLZ/8O64hsvn68GmxqO9vP8giWWcZNy/CsmOecllOB1NFXpCwQ1TBw+P4n84oj2YHwdSzGcre8j/OiAChHl6QHFtAuFvOdVRYFeyurFM8KP6Bb6tEeDDrqILboaQtTJOwRD2Fkt33C5lpuZNNGqc+DmRjDabgC3ZgzRCe3OyYbhaRlfiwVHFPYt7pDQMnrp/dUmyBSs/6gwd2CiK3cV4ZvpOzyGdynPqXsxIIBIKw== root@test

到此信任添加就完成了,192.168.0.177就可以无密码远程登录192.168.0.178服务器了,如果要想实现双向信任请在192.168.0.178
重复以上步骤,写本文目的只是想把会的东西记录下来,以备遗忘之时查阅!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    CentOS系统中一键安装Openstack图文教程
    下一条:
    Linux中使用crontab命令启用自定义定时任务实例
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 掌握Linux的xargs命令,效率提升10倍(0个评论)
    • 在Linux系统中如何判断Crontab(定时任务)是否正常执行(1个评论)
    • nginx + keepalived实现高可用示例流程步骤(0个评论)
    • ubuntu 22.04系统中报错:Python 3.6 is no longer supported by the Python core team...解决方式(1个评论)
    • 近期文章
    • 在laravel10+框架中使用vant4实现多个单页面路由(0个评论)
    • 在laravel10+框架中使用vant4库流程步骤(0个评论)
    • 在ubuntu系统中实现mysql数据存储目录迁移流程步骤(0个评论)
    • 在mysql中使用存储过程批量新增测试数据流程步骤(0个评论)
    • docker + gitea搭建一个git服务器流程步骤(0个评论)
    • Laravel 10.34版本发布(0个评论)
    • PHP8中的JIT编译器可以将代码性能提高20%以上(0个评论)
    • 在php语言中实现网站ssl证书过期时间检查功能示例代码(0个评论)
    • 在php语言中实现谷歌登陆功能:google授权api示例代码(0个评论)
    • 在php语言中实现文件加密功能示例(0个评论)
    • 近期评论
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 路人 在

      php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..
    • 博主 在

      科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 @ mashrdn 多切换几个节点测试,免费ssr是没那么稳..
    • mashrdn 在

      科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 V2rayn免费节点添加上去了,youtobe无法打开网页,是怎么回事..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客