Linux系统的远程登陆管理

一、Openssh的功能

1、sshd服务的用途
#作用
#可以实现通过网络在远程主机中开启安全shell的操作
Secure SHell ====》ssh #客户端
Secure SHell daemom ==》#服务端
2、安装包: openssh-server
3、主配置文件: /etc/ssh/sshd_conf
4、默认端口:22
5、客户端命令: ssh

二、ssh

命令 功能
ssh [-l 远程主机用户] <ip/hostname>
ssh -l root 172.25.254.4 通过ssh命令在4主机中以root身份开启远程shell

Linux系统的远程登陆管理

作用

当输入后,主机会向当前主机发送身份公钥,并保存此公钥到~/.ssh/know_hosts
如果身份验证改变,拒绝连接会出现以下效果
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:qFJoGa0HY3fBnHaMwCBhq5d017at0BcRdOJ3kULqrDM.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:1
ECDSA host key for 172.25.254.4has changed and you have requested strict checking.
Linux系统的远程登陆管理

当连接因为认证问题被拒绝时解决方案

vim ~/.ssh/know_hosts ###在这个文件中删除报错的相应的提示的行即可
Linux系统的远程登陆管理

ssh 常用参数

ssh -l 指定登录用户

Linux系统的远程登陆管理

ssh -i 指定私钥
ssh -X 开启图像

Linux系统的远程登陆管理

ssh -o 指定连接参数#ssh -l [email protected] -o

Linux系统的远程登陆管理

ssh -f 后台运行

Linux系统的远程登陆管理

ssh -t 指定连接跳板

Linux系统的远程登陆管理

三、sshd key认证

1、认证类型

#对称加密
加密和解密是同以以一串字符
容易泄漏可暴力**容易遗忘
#非对称加密
加密用公钥,解密用私钥
不会被盗用
攻击者无法通过无**方式登陆服务器

2、生成非对称加***

方法一:ssh-******
Linux系统的远程登陆管理
Generating public/private rsa key pair. Enter file in which to save the key (/home/lee/.ssh/id_rsa): ##输入保存**文件Enter passphrase (empty for no passphrase): ##**密码Enter same passphrase again: ##确认密码Your identification has been saved in /home/lee/.ssh/id_rsa.##私钥Your public key has been saved in /home/lee/.ssh/id_rsa.pub.##公钥The key fingerprint is:SHA256:rrbJoCb/f+7m5KwEOj2+M2NaCFAg6kxyOuuB+c3kmi8 [email protected]_student7.westos.orgThe key’s randomart image is:
±–[RSA 3072]----+
|o… |
|o. |
|+… |
|*o |
|+o . S |
|.= + . . |
|+.+ * . o |
|[email protected]==.o |
| =BBOBBO
|
±—[SHA256]-----+
方法二:ssh-****** -f /root/.ssh/id_rsa -P “”

3、对服务器加密

#ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
例:ssh-copy-id -i /home/linux/.ssh/id_rsa.pub [email protected]
Linux系统的远程登陆管理

四、sshd安全优化参数详解

#首先输入setenforce 0
systemctl disable --now firewalld
Linux系统的远程登陆管理

Port 2222 设定端口为2222

Linux系统的远程登陆管理
Linux系统的远程登陆管理

PermitRootLogin yes/no 对超级用户登陆是否禁止

Linux系统的远程登陆管理
Linux系统的远程登陆管理

PasswordAuthentication yes/no 是否开启原始密码认证方式

Linux系统的远程登陆管理
Linux系统的远程登陆管理

AllowUsers lee 用户白名单,只允许登陆lee用户

Linux系统的远程登陆管理
Linux系统的远程登陆管理

DenyUsers lee 用户黑名单,只不允许登陆lee用户

Linux系统的远程登陆管理
Linux系统的远程登陆管理