1. 基础命令
lsof -i:20022
semanage port -l|grep ssh
yum install policycoreutils-python
semanage port -a -t ssh_port_t -p tcp 20022
netstat -an | grep 20022
vi /etc/ssh/sshd_config
Port 22 //默认使用22端口,也可以自行修改为其他端口,但登录时要打上端口号
PermitRootLogin //禁止以root远程登录
PasswordAuthentication yes //启用口令验证方式
PermitEmptyPassword //禁止使用空密码登录
LoginGraceTime 1m //重复验证时间为1分钟
MaxAuthTimes 3 //最大重试验证次数
2. 限制远程登录
vim /etc/ssh/sshd_config
AllowUsers oper1 //加@可以限制IP
AllowUsers aliyun test@192.168.1.1
DenyUsers zhangsan aliyun
3. 配置免密互信
ssh-keygen -t rsa
ssh-copy-id 192.168.202.133
4. 远程执行命令
$ ssh root@ip "df -h"
$ ssh nick@ip "pwd; cat hello.txt"