ssh远程管理及控制

本文介绍了SSH的基础知识,包括其加密和压缩特性,以及常用的SSH客户端。深入讲解了SSH的公钥传输原理,描述了客户端和服务端如何通过公钥建立安全连接。此外,还探讨了轻量级自动化运维工具pssh,阐述了它的功能和使用方法,以及在CentOS7系统中的安装配置过程。pssh是进行多台服务器批量操作的有效工具。
摘要由CSDN通过智能技术生成

 

目录

一、SSH基础

二、公钥传输原理

三、轻量级自动化运维工具pssh

 四、总结:


一、SSH基础

定义:SSH(Secure Shell)是一种安全通道协议,主要用来实现字符界面的远程登录、远程 复制等功能;

SSH 协议对通信双方的数据传输进行了加密处理,其中包括用户登录时输入的用户口令;

SSH 为建立在应用层和传输层基础上的安全协议。对数据进行压缩,加快传输速度。

SSH客户端<--------------网络---------------->SSH服务端

优点:数据传输是加密的,可以防止信息泄漏;

           数据传输是压缩的,可以提高传输速度

常见的SSH协议

客户端: Linux Client: ssh, scp, sftp,slogin Windows Client:xshell, MobaXterm,putty, securecrt, sshsecureshellclient

OpenSSH 是实现SSH协议的开源软件项目,适用于各种UNIX、 Linux 操作系统。

Centos 7系统默认已安装openssh相关软件包,并将sshd 服务添加为开机自启动。

执行"systemctl start sshd"命令即可启动sshd 服务

sshd 服务默认使用的是TCP的22端口,安全协议版本sshv2,出来2之外还有1(有漏洞)

二、公钥传输原理

 

客户端发起链接请求

服务端返回自己的公钥,以及一个会话ID(这一步客户端得到服务端公钥)

客户端生成密钥对

客户端用自己的公钥异或会话ID,计算出一个值Res,并用服务端的公钥加密

客户端发送加密后的值到服务端,服务端用私钥解密,得到Res

服务端用解密后的值Res异或会话ID,计算出客户端的公钥(这一步服务端得到客户端公钥)

最终:双方各自持有三个秘钥,分别为自己的一对公、私钥,以及对方的公钥,之后的所有通讯都

会被加密

[root@localhost ~]# ssh root@192.168.220.100
The authenticity of host '192.168.220.100 (192.168.220.100)' can't be established.
ECDSA key fingerprint is SHA256:aArqOlCuamj26GHgAEzFwgCWbz8diDjtQxLvmoXmnM4.
ECDSA key fingerprint is MD5:5b:06:9f:24:20:cb:08:c7:f3:d6:20:ff:56:9c:95:9f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.220.100' (ECDSA) to the list of known hosts.
root@192.168.220.100's password:                              //第一次远程需要输入密码,后面再次登录就不需要输入了
Last login: Wed Oct 27 16:14:59 2021 from 192.168.220.1

 

三、轻量级自动化运维工具pssh

pssh:基于python编写,可在多台服务器上执行命令的工具,也可实现文件复制,提供了基于ssh

和scp的多个并行工具,项目:http://code.google.com/p/parallel-ssh/

pdsh:Parallel remote shell program,是一个多线程远程shell客户端,可以并行执行多个远程

主机上的命令。 可使用几种不同的远程shell服务,包括rsh,Kerberos IV和ssh,项目: https://p

dsh.googlecode.com/

mussh:Multihost SSH wrapper,是一个shell脚本,允许使用命令在多个主机上通过ssh执行命

令。 可使用ssh-agent和RSA/DSA密钥,以减少输入密码,项目:http://www.sourceforge.net/pr

ojects/mussh

pssh 命令选项如下:

-H:主机字符串,内容格式”[user@]host[:port]”
-h file:主机列表文件,内容格式”[user@]host[:port]”
-A:手动输入密码模式
-i:每个服务器内部处理信息输出
-l:登录使用的用户名
-p:并发的线程数【可选】
-o:输出的文件目录【可选】
-e:错误输出文件【可选】
-t:TIMEOUT 超时时间设置,0无限制【可选】
-O:SSH的选项
-P:打印出服务器返回信息
-v:详细模式
–version:查看版本

 pssh配置步骤

#安装pssh需要配置开发源

[root@localhost ~]# cd /etc/yum.repos.d					///etc/yum.repos.d
[root@localhost yum.repos.d]# vim CentOS-Base.repo 		//进入配置文件后大G到行末添加配置文件
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64
        https://mirrors.cloud.tencent.com/epel/$releasever/x86_64
        https://mirrors.huaweicloud.com/epel/$releasever/x86_64
        https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/x86_64
gpgcheck=0
[root@localhost yum.repos.d]# yum clean all
[root@localhost ~]# yum install -y pssh
已加载插件:fastestmirror, langpacks
  正在安装    : pssh-2.3.1-5.el7.noarch                                                       1/1 
  验证中      : pssh-2.3.1-5.el7.noarch                                                       1/1 

已安装:
  pssh.noarch 0:2.3.1-5.el7                                                                       

完毕!
[root@localhost ~]# ssh-keygen 									//生成密钥,然后一路回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
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:
SHA256:BBoNgWZKVFV3Xo8zBOe451fzl0qR9x8CNvVIfXVq7cs root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|...o==o. . o.+  o|
| .+  o... o * +oo|
|.+  .   .  o Booo|
|.      .    +.*..|
|        S  = = +o|
|          . = + B|
|             + E+|
|            . + +|
|             .  .|
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id 192.168.59.110					//输入Ip管理客户端
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.59.110 (192.168.59.110)' can't be established.
ECDSA key fingerprint is SHA256:MW/hyNwCd0Qx/OccVIi5+EjHt6U8V3MoxBx5LAqOC3c.
ECDSA key fingerprint is MD5:df:30:2a:42:8b:fc:aa:3d:27:00:6e:9d:4a:4b:6c:e9.
Are you sure you want to continue connecting (yes/no)? yes
/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@192.168.220.128's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.59.110'"
and check to make sure that only the key(s) you wanted were added.

 

 

 

 

 四、总结:

本章讲述了pssh配置过程及命令,客户机管理在20台以下时都可以使用pssh进行管理,希望会对小伙伴们有些帮助

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值