把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. EF - Database First 开发方式

    概述 Database First 又叫数据库优先的开发方式,是一种比较旧的开发方式,现在越来越多的企业已经不再使用此种开发方式. 当然,对于一些旧项目进行升级,在已经有了数据库的情况下,使用此种方式 ...

  2. mysqldump导出报错"mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `file_storage` at row: 29"

    今天mysql备份的crontab自动运行的时候,出现了报警,报警内容如下 mysqldump: Error 2013: Lost connection to MySQL server during ...

  3. 【LeetCode】字符串匹配

    给定目标串 haystack 和模式串 needle ,返回 needle 在 haystack 中第一次出现的位置下标,若 needle 不是 haystack 的子串则返回 -1. 1. Brut ...

  4. 小程序util工具

    import wafer from '../lib/wafer2-client-sdk' import tip from './tip' // 时间格式化 const formatTime = tim ...

  5. 把旧系统迁移到.Net Core 2.0 日记 (12) --发布遇到的问题

    1. 开发时是在Mac+MySql, 尝试发布时是在SQL2005+Win 2008 (第一版) 在Startup.cs里,数据库连接要改,分页时netcore默认是用offset关键字分页, 如果用 ...

  6. 在eclipse激活maven profile配置

    profile简介 profile可以让我们定义一系列的配置信息,然后指定其激活条件.这样我们就可以定义多个profile,然后每个profile对应不同的激活条件和配置信息,从而达到不同环境使用不同 ...

  7. linux系统管理 启停命令

    mac下Linux的登录命名 'ssh -l root 192.168.10.109' password: xxxx ​ 退出登录 >> logout shutdown命令 要使用这个命令 ...

  8. Java工厂方法模式

    工厂方法模式: /** * 工厂方法模式:也叫工厂模式,属于创建型模式,父类工厂(接口)负责定义产品对象的公共接口, * 而子类工厂负责创建具体的产品对象. * 目的:是为了把产品的实例化操作延迟到子 ...

  9. python if elif else判断语句

    username = 'jack' password = ' _username = input('username') _password = input('password') if userna ...

  10. js 动态绑定鼠标事件

    <script> function getElementsByClassName(n) { var classElements = [],allElements = document.ge ...