linux 密钥远程登录和防火墙设置

一、今天搭建好基本环境后,要做安全管理,里面就涉及到密钥远程登录,同时还有SSH配置和禁止Root远程登陆设置。

参考:

http://zengweidao.blog.51cto.com/8342699/1437979

http://matt-u.iteye.com/blog/851158

配置ssh

vi /etc/ssh/sshd_config

重新启动服务:
cd /etc/init.d  
./sshd restart

参考里面的文章生成私钥和公钥之后,传到服务器,赋予.ssh目录755的权限,同时赋予authorized_keys也是755的权限,

最后用密钥登录时,提示:“所选的用户密钥未在远程主机上注册” ,搜了百度发现很多都说是:检查服务器的selinux及iptables是否开启。

但我查询防火墙:

# service iptables status
iptables: Firewall is not running.

# sestatus
SELinux status:                 disabled

最后发现要把.ssh目录设置为700 ,公钥authorized_keys也是600的权限 就可以了。

虽然该文章没什么 含金量,但好脑子不如烂笔头先记录下了,也供同样问题的朋友解愁,因为网上搜索后发现暂时没有指明这个问题的。

注意:今天配置完之后,发现密钥登录不可以,发现要把 SELinux status:  设置为disabled。

[root@localhost ~]# vim /etc/selinux/config

修改 selinux 配置文件

将SELINUX=enforcing改为SELINUX=disabled,保存后退出

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcingSELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

此时获取当前selinux防火墙的安全策略仍为Enforcing,配置文件并未生效。

[root@localhost ~]# getenforce
Enforcing

重启

[root@localhost ~]# reboot

二、防火墙设置和说明这里就不写了,直接参考网上

cat /etc/sysconfig/iptables 查看当前防火墙配置

http://www.360doc.com/content/11/0416/17/2104556_110100707.shtml   详细说明

http://www.cnblogs.com/JemBai/archive/2009/03/19/1416364.html  详细使用加说明

http://www.linuxidc.com/Linux/2012-08/67952.htm  规则详解

http://www.linuxidc.com/Linux/2013-08/88535.htm

1、普通操作命令

service  iptables  status        查看防火墙状态
service  iptables  start           开启防火墙
service  iptables  stop           关闭防火墙
service  iptables  restart        重启防火墙

2、重启防火墙,这里有两种方式重启防火墙
  a) 重启后生效
  开启: chkconfig iptables on
  关闭: chkconfig iptables off
 
  b) 即时生效,重启后失效
  开启: service iptables start
  关闭: service iptables stop

三、CentOS 7.0默认使用的是firewall作为防火墙

查看防火墙状态

firewall-cmd --state

停止firewall

systemctl stop firewalld.service

禁止firewall开机启动

systemctl disable firewalld.service 

转自:CentOS 6和CentOS 7防火墙的关闭

Centos7开放及查看端口
https://www.cnblogs.com/heqiuyong/p/10460150.htm

– 开放指定端口
firewall-cmd --zone=public --add-port=1935/tcp --permanent

– 关闭指定端口
firewall-cmd --zone=public --remove-port=5672/tcp --permanent

– 重启防火墙
firewall-cmd --reload

--查看防火墙所有开放的端口

firewall-cmd --zone=public --list-ports

--关闭防火墙

如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估

systemctl stop firewalld.service

--查看防火墙状态

 firewall-cmd --state

--查看监听的端口

netstat -lnpt

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值