文章目录
远程访问与控制
ssh远程管理
大多数企业服务器是通过远程登录的方式来进行管理的
配置Open SSH服务端
ssh协议
为客户机提供安全的shell环境,用于远程管理,默认端口:TCP 22
openshh服务了解
服务名称:sshd
服务端主程序:/usr/sbin/sshd
服务端配置文件:/etc/ssh/sshd_config
ssh_config:针对客户端
sshd_config:针对服务端
访问形式 | 端口号 |
---|---|
SSH:密文访问默认端口 | TCP:22,一般广域网 |
Telnet:明文形式的访问 | TCP 23,一般局域网 |
远程桌面 | 3389,图形化界面 |
了解SSH服务
[root@localhost ~]# vi /etc/ssh/sshd_config
#Port 22 端口号
#AddressFamily any
#ListenAddress 0.0.0.0 监听地址
#ListenAddress ::
openSSH用户登录控制
shhd服务默认是允许root用户登录,在使用internet是不安全,普遍做法是:禁止root用户,空密码用户,登录时间,重试次数
AllowUsers(白名单,仅允许,只有这些可以登录)
DenyUsers(黑名单,仅拒绝,只有这些不行)
AllowUsers不可与DenyUsers同时使用
[root@localhost ~]# vim /etc/ssh/sshd_config
#LoginGraceTime 2m 会话时间,设置指定时间内没有成功登录,将会断开连接
#PermitRootLogin yes 是否允许root登录,默认为允许
#StrictModes yes 是否允许root登录,默认为允许
#MaxAuthTries 6 密码最大验证次数
#MaxSessions 10 最大会话连接数量
登录验证方式
密码验证:核对用户名,密码是否匹配
扫描二维码关注公众号,回复:
11563717 查看本文章
密钥对验证:核对客户的私钥,服务端公钥是否匹配
公钥:服务器使用
私钥:客户保留
非对称秘钥:RSA
对称秘钥:3DES,AES
[root@localhost ~]# vi /etc/ssh/sshd_config
#PasswordAuthentication yes 是否使用密码
#PermitEmptyPasswords no 禁止空密码
PasswordAuthentication yes 是否需要密码验证
补充
如果test01中有其他用户,而我又知道其中某个用户的密码,那么使用su命令不就可以切换到root这时候加入wheel组的用户tom可以切换root权限,而tom1不行,所以在修改PermitRootLogin参数时候别忘了启用PAM认证模块
使用SSH客户端程序
SSH客户端程序命令
ssh命令–远程安全登录
[root@wanwu ~]# ssh [email protected]
[email protected]'s password: 验证root密码
Permission denied, please try again.
[email protected]'s password:
Last failed login: Thu Jul 9 17:24:46 CST 2020 from 192.168.136.100 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Thu Jul 9 17:24:25 2020 from 192.168.136.2
[root@lisi ~]#
scp命令——远程安全复制
基本命令{文件和目录复制}
[root@wanwu opt]# scp -r text/ [email protected]:/home/ 将本机目录text/以root权限复制到192.168.136.190中的home下
[root@wanwu opt]# scp ssh_shbi123 [email protected]:/home/ 将本机文本ssh_shbi123/以root权限复制到192.168.136.190中的home下
sftp命令–安全FTP上下载
命令基本格式
sftp user@host
get:下载
put:上传
[root@wanwu opt]# sftp [email protected] 在192.168.136.190下面的home目录下
[email protected]'s password:
Connected to 192.168.136.190.
sftp> ls
Xshell
强大的安全终端模拟软件
密钥对验证的SSH体系
创建密钥对图解
创建密钥对
在客户机中创建密钥对
ssh-keygen命令
可用的加密算法:RSA或DSA 或ecdsa 椭圆曲线加密
[root@test02]# ssh-keygen -t ecdsa
Enter file in which to save the key (/root/.ssh/id_ecdsa): # 指定出秘钥存放路径
Enter passphrase (empty for no passphrase): ## 输入秘钥对密码
Enter same passphrase again: ## 再次确认密码
Your identification has been saved in /root/.ssh/id_ecdsa.
Your public key has been saved in /root/.ssh/id_ecdsa.pub.
The key fingerprint is:
SHA256:BiFecEuu1UyGxVx6xWEWDYEiFb3hGXX9SnnhpPiAzDE root@wanwu
The key's randomart image is:
+---[ECDSA 256]---+
| o.=**+.+X*.. |
| . *oB+E=+...o.|
| . =.*o==. +.o|
| o . =+o .o.o|
| . S o. o |
| . .. |
| |
| |
| |
+----[SHA256]-----+
查看密钥
[root@test02]# ls -a 家目录下面的.ssh
. .. anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc .cshrc .ssh .tcshrc .viminfo
[root@test02]# cd .ssh/
[root@test02]# ls
id_ecdsa id_ecdsa.pub known_hosts 公钥和私钥生成
上传公钥文件 id_rsa.pub,秘钥对已经生成,公钥上传到服务端
[root@test02 ]# ssh-copy-id -i id_ecdsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_ecdsa.pub"
/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: ## 输入tom用户的密码
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
进入make查看
[make@test01 .ssh]$ ls
authorized_keys known_hosts ## 秘钥已经上传
## 查看一下公钥内容:
[make@test01 .ssh]$ cat authorized_keys
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBB6eSY2pLpU2MM2xT8hGpM5ogSVOLCbgtHxNnzAIg+lsxG95kkSV8LN++6q9IhRpTxyXdt86bs5hznP+JfWxpgk= root@test02
## 可以看出是test02的make用户上传的
[root@test02 .ssh]# ssh [email protected]
Enter passphrase for key '/root/.ssh/id_ecdsa': 输入密钥对密码
Last login: Sat Jul 11 21:31:11 2020
[tom@test01 ~]$ 成功
免密登陆
[root@test02 .ssh]# ssh-agent bash ## 代理bash终端
[root@test02 .ssh]# ssh-add ## 添加免密登陆的密码
Enter passphrase for /root/.ssh/id_ecdsa: ## 输入创建秘钥对时的密码
Identity added: /root/.ssh/id_ecdsa (/root/.ssh/id_ecdsa)
TCP Wrappers控制
保护原理
查看文件是否存在
[root@localhost etc]# ls ./ | grep *.allow
hosts.allow
[root@localhost etc]# vi hosts.allow 白名单
sshd:192.168.136.218 仅允192.168.136.218IP访问ss
[root@localhost etc]# vi hosts.deny 黑名单
shhd:ALL 禁止其他所有地址访问
白名单优先
保护原理
查看文件是否存在
[root@localhost etc]# ls ./ | grep *.allow
hosts.allow
[root@localhost etc]# vi hosts.allow 白名单
sshd:192.168.136.218 仅允192.168.136.218IP访问ss
[root@localhost etc]# vi hosts.deny 黑名单
shhd:ALL 禁止其他所有地址访问
白名单优先