1. SSH基本概念?
ssh是一个应用层安全协议
2.SSH主要的功能是?
实现远程登录, 数据传输过程中进行加密. 钉钉(澡堂模式)
远程登录:
ssh
telnet
3.SSH与Telnet之间有什么区别?
服务连接方式 | 服务数据传输 | 服务监听端口 | 服务登陆用户 |
---|---|---|---|
ssh | 加密 | 22/tcp | 默认支持root用户登陆 |
telnet | 明文 | 23/tcp | 不支持root用户登陆 |
4.抓包分析SSH与Telnet的区别?
所需工具:Wireshark
[[email protected] ~]# yum install telnet-server -y
[[email protected] ~]# systemctl start telnet.socket
[[email protected] ~]$ echo oollddbbooyy |sed -r 's#(.)(.)#\1#g'
oldboy
PS:
服务器都是使用的SSH协议实现的远程登录
对于路由器 交换机 全是走的telnet协议 ( Web界面调试 )
5.SSH相关客户端指令ssh、scp、sftp?
1.ssh ( Windows系统:①Xshell ②Crt ) ( Mac系统: ①ssh命令 ②Crt )
[[email protected] ~]# ssh [email protected]
[email protected]'s password:
2.scp: rsync增量 scp 全量(每次都是覆盖) ssh协议
拷贝目录 需要 -r参数
推送
[[email protected] ~]# scp ./web-file [email protected]:/tmp
获取
[[email protected] ~]# scp [email protected]:/tmp/web-file ./test
限速 ( kb 1024 * 8 = 实际的传输速率 )
[[email protected] ~]# scp -l 8192 ./1.txt 172.16.1.41:/tmp
[email protected]'s password:
1.txt 14% 74MB 1.0MB/s 07:09
3.sftp 文件传输协议?
为什么不适用命名的方式? 为什么使用xftp?
1.简单,带图形,支持断点续传,支持暂停
6.SSH远程登录方式、用户密码、秘钥方式?
1.基于用户和密码的方式
1.密码太复杂容易忘 工具:lastpass(适用于多终端)
2.密码太简单不安全
2.基于密钥的方式实现 (指纹)
1.降低密码泄露风险
2.提升用户的便捷性
3.实现免密码登录方式
3.1创建一对密钥 公钥+私钥 ==配套
[[email protected] ~]# ssh-keygen -C [email protected] //一路回车即可
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:gk2zFs5LuoV4Jf381EaFnaHvRZu36qLqIcYUma17SeU [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| . |
| + + o |
| ++. . o + .|
| Bo+o o .o|
| [email protected] . .oo|
| .oBo=. o . .o|
| . +=o+o . o .. |
| ..oo .o o . |
| . .o..o oo |
+----[SHA256]-----+
3.2 将管理机的公钥推送至web服务器上 ( 需要输入对端服务器的密码 )
[[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.16.1.7 (172.16.1.7)' can't be established.
ECDSA key fingerprint is SHA256:INgxiiDMWAw79GeJRGUjsLmXJmXbHDXyAJqV8wFxhpI.
ECDSA key fingerprint is MD5:78:6a:d4:ad:13:4a:c9:17:cb:3a:4d:cf:2f:c8:2c:08.
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
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
3.3 使用 ssh 命令 连接 对应的服务器 ( 检查是否免密码 )
[[email protected] ~]# ssh '[email protected]'
3.4有问题查看日志信息
tail -f /var/log/secure
7.SSH场景实践,借助SSH免秘实现跳板机功能?
8.SSH远程连接功能安全优化? fail2ban又是啥?(研究)
1.更改远程连接登陆的端口 port 6666
2.禁止ROOT管理员直接登录 PermitRootLogin no
直接 xshell -->root --> server (禁止用户名密码 禁止密钥)
间接 xshell -->oldxu --> server ---> su - root
3.密码认证方式改为密钥认证 PasswordAuthentication no
4.重要服务不使用公网IP地址 !!!!!!!!!!!!!!!!!
5.使用防火墙限制来源IP地址 软件防火墙 | 硬件防火墙
10.0.0.1(其他人) ---> 10.0.0.61 异常
10.0.0.100(公司) ---> 10.0.0.61 正常
6.修改后的配置 [测试完后记得还原]
[[email protected] ~]# vim /etc/ssh/sshd_config
Port 6666 # 变更SSH服务远程连接端口
PermitRootLogin no # 禁止root用户直接远程登录
PasswordAuthentication no # 禁止使用密码直接远程登录
UseDNS no # 禁止ssh进行dns反向解析,影响ssh连接效率参数
GSSAPIAuthentication no # 禁止GSS认证,减少连接时产生的延迟
域名解析IP
IP解析域名
9.fail2ban(研究)
ail2ban可以监控系统日志,并且根据一定规则匹配异常IP后使用Firewalld将其屏蔽,尤其是针对一些爆破/扫描等非常有效。
1.开启Firewalld防火墙
[[email protected] ~]# systemctl start firewalld
[[email protected] ~]# systemctl enable firewalld
[[email protected] ~]# firewall-cmd --state
running
2.修改firewalld规则,启用Firewalld后会禁止一些服务的传输,但默认会放行常用的22端口, 如果想添加更多,以下是放行SSH端口(22)示例,供参考:
#放行SSHD服务端口
[[email protected] ~]# firewall-cmd --permanent --add-service=ssh --add-service=http
#重载配置
[[email protected] ~]# firewall-cmd --reload
#查看已放行端口
[[email protected] ~]# firewall-cmd --list-service
3.安装fail2ban,需要有epel
[[email protected] ~]# yum install fail2ban fail2ban-firewalld mailx -y
4.配置fail2ban规则.local会覆盖.conf文件
[[email protected] fail2ban]# cat /etc/fail2ban/jail.local
[DEFAULT]
ignoreip = 127.0.0.1/8
bantime = 86400
findtime = 600
maxretry = 5
banaction = firewallcmd-ipset
action = %(action_mwl)s
[sshd]
enabled = true
filter = sshd
port = 22
action = %(action_mwl)s
logpath = /var/log/secure
5.启动服务,并检查状态
[[email protected] ~]# systemctl start fail2ban.service
[[email protected] ~]# fail2ban-client status sshd
6.清除被封掉的IP地址
[[email protected] ~]# fail2ban-client set sshd unbanip 10.0.0.1
10.SSH如何结合Google Authenticator 实现双向验证? (适合个人使用)
基于密码 + 动态口令 支持
基于密钥 + 动态口令 不支持
https://www.xuliangwei.com/bgx/1345.html
原文地址:https://www.cnblogs.com/yinwu/p/11509289.html
时间: 2024-10-03 08:45:49