1.修改ssh端口
打开 sshd_config 文件
vim /etc/ssh/sshd_config
找到 Port,取消#注释,修改端口号,保存退出。
在ufw中添加对应的端口号放行。
ufw allow #Port#
重启sshd服务
service sshd restart
最后用ssh工具登录查看是否已经生效
2.ssh使用密钥登陆
建立密钥对
ssh-keygen
安装公钥
cd .ssh
cat id_rsa.pub >> authorized_keys
修改文件权限
chmod 600 authorized_keys
chmod 700 ~/.ssh
在sshd_config修改使用密钥登陆
RSAAuthentication yes
PubkeyAuthentication yes
重启sshd服务
service sshd restart
测试使用密钥登陆成功后修改为禁止密码登陆
PasswordAuthentication no
3.设置ssh无操作超时时间
设置了ServerAliveInterval 以后ssh永远不会超时
ServerAliveInterval 60 #每60秒向客户端发送一次确认连接信号
ServerAliveCountMax 1 #客户端1次未响应就断开连接