把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. CSS知识点(三)

    十三.标准文档流. 标准文档流下有哪些微观现象? 1.空白折叠现象 多个空格会被合并成一个空格显示到浏览器页面中.img标签换行写.会发现每张图片之间有间隙,如果在一行内写img标签,就解决了这个问题 ...

  2. Utils--Cookie工具类

    Utils--Cookie工具类 package com.taotao.manage.util; import java.io.UnsupportedEncodingException; import ...

  3. 解决iOS第三方SDK之间重复的symbols问题

    前言:今天公司项目准备使用高德导航,其中用到了高德3D地图SDK,然后就出现bug了.在真机上可以完美运行,但是在模拟器上,就出现了一大片的bug:提示有82个Duplicate symbols,仔细 ...

  4. ActiveMQ producer不断发送消息,会导致broker内存耗尽吗?

    http://activemq.apache.org/my-producer-blocks.html 回答了这个问题: ActiveMQ 5.x 支持Message Cursors,它默认把消息从内存 ...

  5. leetcode Most Common Word——就是在考察自己实现split

    819. Most Common Word Given a paragraph and a list of banned words, return the most frequent word th ...

  6. Linux使用ntpdate和ntpd进行时间同步

    生产环境关联主机间常要求时间一致,若有NTP时间同步服务器,可配置各主机与时间同步服务器同步时间. 1.使用ntpdate进行时间同步 安装ntp客户端: yum install ntpdate 同步 ...

  7. git 从远程拉取代码、推代码的步骤

    (注:如果是几个人共同管理项目,并且你的队友在你之前推过代码,那你就需要 git pull 一下,把代码拉到本地,解决一下冲突,再执行以下步骤,将本地代码推到远程仓库.) 第一步:查看当前的git仓库 ...

  8. charles抓包工具使用方法

    注意: 1.软件安装证书,移动端安装证书: 2.设置SSL proxying setting: 3.设置Map Remote: 这里主要是为了设置移动端代理服务器,让其重定向到想要连接的环境上,比如手 ...

  9. std::string find 的返回值

    std::string  的方法 find,返回值类型是std::string::size_type, 对应的是查找对象在字符串中的位置(从0开始), 如果未查找到,该返回值是一个很大的数据(4294 ...

  10. Win10系列:VC++ Direct3D模板介绍1

    Visual Studio为开发Direct3D应用程序提供了便捷的模版,读者可以不必手动去新建Direct3D中所使用到的基础资源,而只需专注于图形的绘制.本小节主要为读者介绍这个模版中用于绘制图形 ...