把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)的更多相关文章
-
Linux修改SSH端口和禁止Root远程登陆
Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...
-
【转】Linux修改SSH端口和禁止Root远程登陆
Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...
-
Debian修改ssh端口和禁止root远程登陆设置
linux修改端口22vi /etc/ssh/sshd_config找到#port 22将前面的#去掉,然后修改端口 port 1234重启服务就OK了service sshd restart或/et ...
-
centos修改SSH端口并禁用root远程登录
1.使用 root 用户执行以下步骤:只在 CentOS 6.5 下验证. 2.先查看下服务器端口号范围: # sysctl -a|grep ip_local_port_range 3.修改端口 vi ...
-
Linux 修改SSH端口及禁用ROOT远程SSH登陆
打开配置文件: vim /etc/ssh/sshd_config 修改Port及PermitRootLogin节点 : //默认为yes 允许 no表示禁止 PermitRootLogin no // ...
-
Linux禁止root远程登录及修改默认端口
1.1 修改SSHD配置,禁止root远程登录 禁止登录之前先穿甲一个可以远程登录的普通用户,以免造成登录不了的情况 [root@jhkj66 ~]# useradd yw001 #创建用户 [roo ...
-
Linux生成ssh密钥免密登录,允许/禁止密码登录,允许/禁止root远程登录,更改ssh端口
进入想要使用密钥登录的用户家目录 cd 或 cd ~ 执行密钥创建命令,不行可能需要下载openssh-server与openssh-client ssh-keygen -t rsa -P " ...
-
linux下禁止root远程登录和添加新用户
https://www.cnblogs.com/jianz/p/7979250.html 一.添加和root权限一样的用户 1. adduser admin passwd admin (修改密码) ...
-
linux下禁止root远程登录
一.添加和root权限一样的用户 1. adduser admin passwd admin (修改密码) 2.修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示 ...
随机推荐
-
Win7重装后,如何删除cygwin目录?
参考: http://blog.csdn.net/zjjyliuweijie/article/details/6577037 http://blog.csdn.net/huangzhtao/artic ...
-
matlab示例程序--Motion-Based Multiple Object Tracking--卡尔曼多目标跟踪程序--解读
静止背景下的卡尔曼多目标跟踪 最近学习了一下多目标跟踪,看了看MathWorks的关于Motion-Based Multiple Object Tracking的Documention. 官网链接:h ...
-
ubuntu 12.04安装jdk1.8
转自http://blog.chinaunix.net/uid-26404477-id-3471246.html 在安装之前,系统没有任何jdk软件,也就是说在终端执行 java -version 将 ...
-
iOS 取得CGimage字节数据的方法
通过我在网上搜索和总结,目前看来,我发现两种比较方便的方式. 1. CGImage -> CGDataProvider -> CFData -> xx * CGDataProvide ...
-
HTML5 总结-地理定位-6
HTML5 地理定位 定位用户的位置 HTML5 Geolocation API 用于获得用户的地理位置. 鉴于该特性可能侵犯用户的隐私,除非用户同意,否则用户位置信息是不可用的. 浏览器支持 Int ...
-
UE4实现描边效果
描边效果属于常见常用的功能,现VR项目中,也需要射线选中一个物体,使物体高亮. 于是在网上找了部分资料,同时也感谢群里的一位大神的提点,总算将描边的功能实现了,这里也写一个简单的示例步骤. 1.我并不 ...
-
C++面向对象的特点
C++面向对象的特点 面向对象的特点主要有: 封装, 继承, 多态; 现在自己的简单理解如下, 但要明白具体怎么实现, 背后的原理是什么? 什么是封装, C++怎么实现封装 封装的大致可以分为: 函数 ...
-
BZOJ 4403: 序列统计 数学 lucas
4403: 序列统计 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4403 Description 给定三个正整数N.L和R,统计长度在 ...
-
MvvmLight框架使用入门(二)
上一篇我们简单对MvvmLight做了介绍.罗列了三个DLL中,各个命名空间下主要类的定义及大致作用.因为只是范范的概论,对于从未接触过MvvmLight的萌新来说,根本就是在晃点他们.不过万事开头难 ...
-
【转】Appium_API(翻译+用法说明)
转自:https://testerhome.com/topics/3711 1.contextscontexts(self): Returns the contexts within the curr ...