一.Openssh的功能
1.sshd服务的用途
#作用:
#可以实现通过网络在远程主机中开启安全shell的操作
Secure SHELL ==>ssh #客户端
Secure SHELL daemon ==>sshd #服务端
2.安装包
openssh-server
3.主配置文件
/etc/ssh/sshd_conf
4.默认端口
22
5.客户端命令
ssh
二.ssh
1.基本用法
ssh [-l 远程主机用户] <ip|hostname>
例如:
ssh -l root 172.25.254.105 ##通过ssh命令再105主机中以root身份开启远程shell
[[email protected]_student3 ~]# ssh -l root 172.25.254.105
The authenticity of host '172.25.254.2 (172.25.254.105)' can't be established.
ECDSA key fingerprint is SHA256:SKiSCS6tySQBeuxXR+gtAErfL5xkAHCVA1hlUEE6LAM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? ##身份证明生成过程确认
#作用:
当输入<yes>后
105主机会向当前主机发送身份公钥,并保存此公钥到~/.ssh/know_hosts
105主机持有私钥,当客户主机再次连接时会对客户主机进行身分验证
如果身份验证改变,则会出现以下效果
##当连接因为认证问题被拒绝时解决方案
vim ~/.ssh/know_hoses ##在此文件中删除报错的行即可
#ssh 常用参数
-l #指定登陆用户
-i #指定私钥
-X #开启图形
-f #后台运行
-o #指定连接参数
# ssh -l [email protected] -o "StrictHostKeyChecking=no" :首次连接不需要输入yes
-t #指定连接跳板
#ssh -l root 172.25.254.1 -t ssh -l root 172.25.254.105
三.sshd key认证
##认证类型##
1.对称加密
加密和解密是同一串字符
缺点:
容易泄露,可暴力**,容易遗忘
2.非对称加密
加密用公钥,解密用私钥
不会被盗用
攻击者无法通过无**方式登录服务器
#生成非对称加***#
#方法一
[[email protected]_student3 ~]# ssh-******
Generating 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:
SHA256:F4VxN2vNZdUCvbQv26WC1LdLTB+/L4zgrFefH8JNG50 [email protected]_student3.westos.org
The key's randomart image is:
+---[RSA 3072]----+
| .o+oo *|
| .o .+*o|
| . .o+o|
| . .o o|
| S .. .E.|
| .o +o=.B|
| + + [email protected]+|
| = o.X +|
| .o ..=+|
+----[SHA256]-----+
方法二
# ssh-****** -f /root/.ssh/id_rsa -P ""
#对服务器加密#
sh-copy-id -i /root/.ssh//id_rsa.pub [email protected]
例如:
ssh-copy-id -i /root/.ssh//id_rsa.pub [email protected]
##四.sshd 安全优化参数详解##
setenforce 0
systemctl disable --now firewalld
Port **** #设定端口为****
PermitRootLogin yes|no #对超级用户登陆是否禁止
asswordAuthentication yes|no #是否开启原始密码认证方式
AllowUsers ***** #用户白名单
DenyUsers ***** #用户黑名单