SSH管理

作者: chenxuyuan123 | 来源:发表于2021-02-25 17:37 被阅读0次

一:SSH工作原理

01 客户端向服务器请求SSH 连接
02 服务端向客户端请求公钥信息
03 上传公钥信息到服务端,服务端收到后存放到/root/.ssh/authorized_keys
04 客户端使用自己的私钥去认证
05 服务端回复认证通过可以连接

二:基于密钥方式实现远程连接

2.1 客户端生成公钥和密钥

 [root@mb01-61 ~]# ssh-keygen     ###一路回车
 [root@mb01-61 ~]# ll .ssh/             ###生成公钥和私钥
 -rw------- 1 root root 1679 Aug  5 22:43 id_rsa
 -rw-r--r-- 1 root root  394 Aug  5 22:43 id_rsa.pub  

通过下面这种方式可以实现免交互生成公钥和密钥
[root@mb01-61 ~]# ssh-keygen -f /root/.ssh/id_rsa -N ''

2.2 将公钥推送到服务端

[root@m01-61 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.1.7

2.3 测试是否能正常

[root@m01-61 ~]# ssh root@172.16.1.7 hostname
web01-7

三:免交互分发公钥

默认正常情况下将公钥推送到服务端.要先确认在手动输入密码

[root@m01-61 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.1.7
 Are you sure you want to continue connecting (yes/no)? 
 root@172.16.1.7's password:

为了方便,我们使用免交互

3.1 解决需要手动确认是否连接

使用参数-o StrictHostKeyChecking=no
[root@m01-61 ~]#  ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.1.8 -o  StrictHostKeyChecking=no
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.16.1.8's password: 

3.2 解决手动输入密码

安装sshpass工具
[root@m01-61 ~]# yum -y install sshpass -y
免交互分发公钥
[root@mb01-61 ~]# sshpass -p123456 ssh-copy-id -i /root/.ssh/id_rsa.pub 172.16.1.31 -o  StrictHostKeyChecking=no

四:优化ssh

vim /etc/ssh/sshd_config
 1:修改ssh端口
  #Port 22            port 6666
 2:不允许外网登录
 #ListenAddress 0.0.0.0                ListenAddress 172.16.1.61  ###这里写本机ip,就是只监听这个网段的ip
  3:不允许密码认证
 PasswordAuthentication yes           PasswordAuthentication no

相关文章

  • SSH服务的搭建

    管理服务 1、什么是SSH? SSH基础服务,SSH是远程连接Linux,管理Linux的服务。Secure Sh...

  • 版本管理GIT-使用流程

    [TOC] 远程的代码管理是基于SSH的,所以使用远程的GIT管理需要配置SSH。 1 配置SSH 在安装好的GI...

  • 8月21日 批量管理

    远程管理服务配置文件 etc/ssh/sshd_config ssh服务端配置文件 /etc/ssh/ssh_co...

  • SSH Key生成步骤

    git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置。 SSH密钥...

  • git新电脑首次使用配置SSH

    git配置SSH Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的...

  • SSH多账号设置

    创建ssh-key 获取ssh 到代码管理网站填充ssh 创建config文件 Host是别名,Hostname是...

  • 使用Alpine linux搭建Ansible多节点管理实验环境

    Ansible是多节点集群管理的利器,默认通过ssh协议来远程执行命令来管理集群,在被管理节点上除了ssh之外不需...

  • SSH管理

    一:SSH工作原理 01 客户端向服务器请求SSH 连接02 服务端向客户端请求公钥信息03 上传公钥信息到服...

  • SSH 管理

    SSH管理,一台设备对应一个平台绑定进行绑定 比如github上 一台电脑,管理对应一个公钥,如果需要多个账号在同...

  • 二、SSHconfig命令

    config方便我们批量管理多个ssh。config存放在 ~/.ssh/ 远程ssh登陆linux服务器 ss...

网友评论

      本文标题:SSH管理

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