把ssh默认远程连接端口修改为3333

1.编辑防火墙配置:

vi /etc/sysconfig/iptables

防火墙新增端口3333,方法如下:

-A INPUT -m state --state NEW -m tcp -p tcp --dport  -j ACCEPT

具体是这样做:

======================================================================
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [:]
:FORWARD ACCEPT [:]
:OUTPUT ACCEPT [:]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

之后,重启防火墙,使配置生效:

/etc/init.d/iptables restart

或者

service iptables restart

防火墙策略都是写在/etc/sysconfig/iptables文件里面的。若是没有发现/etc/sysconfig/下有iptables文件,解决方法:

1. 随便写一条iptables命令配置个防火墙规则。如:iptables -P OUTPUT ACCEPT。

cd /etc/sysconfig/
iptables -P OUTPUT ACCEPT

2. service iptables save进行保存

service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
ls
cbq htcacheclean init modules network quota_nld samba sendmail sshd
console httpd iptables named network-scripts readonly-root sandbox snmpd udev
crond i18n iptables-config netconsole networking rsyslog saslauthd snmptrapd xinetd

3. service iptables restart命令重启:

/etc/init.d/iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: raw filter mangl[ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]

或者

service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: raw filter mangl[ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]

2.备份ssh端口配置文件

cp /etc/ssh/sshd_config    /etc/ssh/sshd_config.bak

或者

cp /etc/ssh/ssh_config    /etc/ssh/ssh_config.bak

修改ssh端口为3333

vi /etc/ssh/sshd_config
Port
Port

把#去掉,在 Port  下方添加 Port  。

重启:

/etc/init.d/sshd restart

service sshd restart

用3333端口可以正常连接之后,再返回去重复上面的步骤。把22端口禁用了,以后ssh就只能用3333端口连接了!增强了系统的安全性。

3、禁止root通过ssh远程登录

vi /etc/ssh/sshd_config

找到PermitRootLogin,将后面的yes改为no,把前面的注释#取消,这样root就不能远程登录了!
可以用普通账号登录进去,要用到root的时候使用命令su root 切换到root账户

4、限制用户的SSH访问

假设我们只要root,user1和user2用户能通过SSH使用系统,向sshd_config配置文件中添加

vi /etc/ssh/sshd_config
AllowUsers root user1 user2

5、配置空闲超时退出时间间隔
用户可以通过ssh登录到服务器,你可以设置一个空闲超时时间间隔。
打开sshd_config配置文件,设置为如下。

vi /etc/ssh/sshd_config
ClientAliveInterval
ClientAliveCountMax

上面的例子设置的空闲超时时间间隔是600秒,即10分钟,
过了这个时间后,空闲用户将被自动踢出出去(可以理解为退出登录/注销)。

6、限制只有某一个IP才能远程登录服务器

vi /etc/hosts.deny     #在其中加入sshd:ALL
vi /etc/hosts.allow #在其中进行如下设置:sshd:192.168.1.1 #(只允许192.168.1.1这个IP远程登录服务器)

最后重启ssh服务:

/etc/init.d/sshd restart

linux修改ssh端口 以及禁止root远程登录 (实验机 CentOs)的更多相关文章

  1. Linux修改SSH端口和禁止Root远程登陆

    Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...

  2. 【转】Linux修改SSH端口和禁止Root远程登陆

    Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...

  3. Debian修改ssh端口和禁止root远程登陆设置

    linux修改端口22vi /etc/ssh/sshd_config找到#port 22将前面的#去掉,然后修改端口 port 1234重启服务就OK了service sshd restart或/et ...

  4. centos修改SSH端口并禁用root远程登录

    1.使用 root 用户执行以下步骤:只在 CentOS 6.5 下验证. 2.先查看下服务器端口号范围: # sysctl -a|grep ip_local_port_range 3.修改端口 vi ...

  5. Linux 修改SSH端口及禁用ROOT远程SSH登陆

    打开配置文件: vim /etc/ssh/sshd_config 修改Port及PermitRootLogin节点 : //默认为yes 允许 no表示禁止 PermitRootLogin no // ...

  6. Linux禁止root远程登录及修改默认端口

    1.1 修改SSHD配置,禁止root远程登录 禁止登录之前先穿甲一个可以远程登录的普通用户,以免造成登录不了的情况 [root@jhkj66 ~]# useradd yw001 #创建用户 [roo ...

  7. Linux生成ssh密钥免密登录,允许/禁止密码登录,允许/禁止root远程登录,更改ssh端口

    进入想要使用密钥登录的用户家目录 cd 或 cd ~ 执行密钥创建命令,不行可能需要下载openssh-server与openssh-client ssh-keygen -t rsa -P " ...

  8. linux下禁止root远程登录和添加新用户

    https://www.cnblogs.com/jianz/p/7979250.html 一.添加和root权限一样的用户 1. adduser admin passwd  admin (修改密码) ...

  9. linux下禁止root远程登录

    一.添加和root权限一样的用户 1. adduser admin passwd  admin (修改密码) 2.修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示 ...

随机推荐

  1. 模拟数据库丢失undo表空间

    数据库无事务情况下丢失undo表空间数据文件 1. 查看当前undo表空间,并删除物理undo文件 SYS@userdata>show parameter undo_tablespace; NA ...

  2. echarts的基本使用

    echarts的基本使用 官网:http://echarts.baidu.com/index.html ECharts,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移 ...

  3. 【转】vue+axios 前端实现登录拦截(路由拦截、http拦截)

    一.路由拦截 登录拦截逻辑 第一步:路由拦截 首先在定义路由的时候就需要多添加一个自定义字段requireAuth,用于判断该路由的访问是否需要登录.如果用户已经登录,则顺利进入路由, 否则就进入登录 ...

  4. Weblogic项目部署教程

    说明: 其实Weblogic是允许直接以文件夹形式发布项目的,WAR包和文件夹发部的效果没有什么区别. 对于Eclipse项目,导出的WAR包其实确实只是项目下的WebContent文件夹中的内容,所 ...

  5. vue cli搭建的vue项目 不小心开了eslint 一直报黄色的警告

    报错必须处理,警告也忍不了,发现在bulid -webpack.base.config.js 里找到 const createLintingRule = () => ({ /*test: /\. ...

  6. python settings :RROR 1130: Host 'XXXXXX' is not allowed to connect to this MySQL server

    pymysql.err.InternalError: (1130, u"Host '127.0.0.1' is not allowed to connect to this MySQL se ...

  7. python 列表切片

    列表切片是python语言独有的特征,大大方便了我们的编码. 首先,在介绍切片之前,必须要知道一个知识,就是python列表的读写,下标可以使用负数. insert,get,set 操作均可传入负数下 ...

  8. learning at command AT+CIMI

    AT command AT+CIMI [Purpose]        Learning how to get the International Mobile Subscriber Identity ...

  9. day20-正则表达式练习

    import re from re import findall,search,S secret_code = 'hadkfalifexxIxxfasdjifja134xxlovexx23345sdf ...

  10. commons-logging 与log4j的关系

    参考:http://zachary-guo.iteye.com/blog/361177