Centos7 配置ssh连接

  Centos7 配置ssh连接
  1.检查是否安装openssh-server:
#yum list installed | grep openssh-server
  安装openssh-server:
#yum install openssh-server
  2.修改sshd_config:
#vi /etc/ssh/sshd_config      #Port 22是linux默认ssh端口,自定义SSH端口必须避开系统已使用端口尽量大于10000修改如下:
#Port 22            #保留这行或者去掉前面‘#’号
Port 10000             #添加要开放的端口

  其他可选配置:
PermitRootLogin yes #开启允许远程登录
PasswordAuthentication yes #开启用户名密码作为连接验证
AllowUsers username #添加限制用户username

  安装policycoreutils-python(可选):
#yum -y install policycoreutils-python

  3.修改SELinux
  查看当前SElinux 允许的ssh端口:
#semanage port -l | grep ssh
  添加10000端口到 SELinux:
#semanage port -a -t ssh_port_t -p tcp 10000
  从SELinux删除10000端口:
#semanage port -d -t ssh_port_t -p tcp 10000
  确认是否添加进去:
#semanage port -l | grep ssh
  开启sshd服务:
#sudo service sshd start
  检查是否开启sshd服务:
#ps -e | grep sshd
  检查10000号端口是否开启监听
#netstat -an | grep 10000
  4.修改防火墙
#vi /etc/sysconfig/iptables
  添加如下:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10000 -j ACCEPT
  重启防火墙iptables:
#systemctl restart iptables.service
  设置开机自启:
#chkconfig sshd on #开机自启
  重启ssh:
#systemctl restart sshd.service

原文地址:https://www.cnblogs.com/zengming/p/8503393.html