CentOS 7 默认使用的是firewall作为防火墙,这里改为iptables防火墙。关闭 firewalld# 查看 firewalld 进程是否启动了[root@localhost ~]# p
CentOS 7 默认使用的是firewall作为防火墙,这里改为iptables防火墙。
关闭 firewalld
# 查看 firewalld 进程是否启动了[root@localhost ~]# ps aux | grep firewalldroot 943 0.0 0.1 327172 26756 ? Ssl 06:09 0:00 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopidroot 51669 0.0 0.0 112668 972 pts/0 S+ 20:45 0:00 grep --color=auto firewalld# 停止 firewalld[root@localhost ~]# systemctl stop firewalld.service [root@localhost ~]# ps aux | grep firewalldroot 51728 0.0 0.0 112664 972 pts/0 S+ 20:45 0:00 grep --color=auto firewalld# 禁止firewall开机启动[root@localhost ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
安装iptables防火墙
yum updateyum install -y vim openssl openssh-server net-toolsyum install iptables-services# ...# 编辑防火墙配置文件vim /etc/sysconfig/iptables# 保存退出:wq! # 最后重启防火墙使配置生效systemctl restart iptables.service# 查看防火墙运行状态systemctl status iptables# 设置防火墙开机启动systemctl enable iptables.service
修改配置文件
vim /etc/ssh/sshd_config将 PermitRootLogin,RSAAuthentication,PubkeyAuthentication 的设置打开。
# Authentication:#LoginGraceTime 2mPermitRootLogin yes#StrictModes yes#MaxAuthTries 6#MaxSessions 10RSAAuthentication yesPubkeyAuthentication yes
启动ssh的服务:
systemctl start sshd.service# orservice sshd restart# or/usr/bin/ssh-keygen -A/usr/sbin/sshd
设置开机自动启动ssh服务
systemctl enable sshd.service