ssh
基本用法
ssh [-l 远程主机用户]<ip|hostname>
建立虚拟机:westos-vmctl rewet westosa westos-vmctl create westosb
给虚拟机改名:hostnamectl set-hostname westosaaaaaaaaaaaa.westos.org
重置网络:nm-connection-editor
保持网络纯净rm -fr /root/.ssh/*
ssh -l root 172.25.254.139
查看#当连接因为认证问题被拒绝时解决方案#
vim ~/.ssh/know_hosts ##在此文件中删除报错提示相应的行即可
#ssh 常用参数#
-l #指定登陆用户
-i #指定私钥
-X #开启图形
-f #后台运行
-o #指定连接参数
# ssh -l root@172.25.254.x -o "StrictHostKeyChecking=no"首次连接不需要输入yes
-t #指定连接跳板
# ssh -l root 172.25.254.1 -t sh -l root 172.25.254.139
###sshd key认证 ####
#1.认证类型#
1.对称加密
加密和解密是同一串字符
容易泄漏
可暴力破解
容易遗忘
2.非对称加密
加密用公钥,解密用私钥
不会被盗用
攻击者无法通过无密钥方式登陆服务器
#2.生成非对称加密密钥#
#方法1
$ ssh-keygen
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:OZVOK9g6NyZsaUIfbZMrfAGB31GQsJ3FyviO4/psVSg root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| +o=o . *|
| . ==+= B+|
| . .oo=+=+*|
| o . oo.Oo+|
| S .* =.|
| = = |
| + + o |
| + E..|
| .+. .|
+----[SHA256]-----+
#方法二
$ssh-keygen -f /root/.ssh/id_rsa -P ""
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.139 查看
服务器加密
查看配置 rpm -qc openssh-server
修改指令vim /etc/ssh/sshd_config passwordAuthentication yes/no
关防火墙setenforce 0 systemctl disable --now firewalld
重置systemctl restart sshd
白名单AllowUsers user1 user2
黑名单DenyUsers user1 user2