chkconfig iptables off 永久关闭防火墙
service iptables stop 临时关闭 service iptables start 临时开启
在虚拟机的Linux上安装好Nginx后,启动Nginx服务,在Linux环境下,输入ip直接可以访问到Nginx的欢迎界面,而在电脑本地访问不到界面,出现错误。
这种情况下,一般是Linux系统的防火墙需要配置,把所需要访问的网络端口开放出去。
查看如下:cd / && cat etc/sysconfig/iptables
添加Nginx的默认端口80: -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
[root@pyy-docker /]# cd / && cat etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
配置完成后,重启防火墙设置 service iptables restart (关键步骤必须重启)
可以访问 Linux部署服务器地址测试了
SElinux(secure enhanced linux )安全增强的Linux
selinux linux中的安全访问策略
运行模式分为三种 enforcing (强制模式)、permissive(宽容模式)、disabled(关闭)
查看状态\
$ sestatus
SELinux status: enabled #开机启动
SELinuxfs mount: /selinux
Current mode: enforcing #强制模式
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
临时
# setenforce 0 #关闭 Selinux
# setenforce 1 #开启 Selinux
永久方式,确实可用,需要重启服务器!
参考 :https://blog.csdn.net/yonggeit/article/details/72388965
1、修改 /etc/selinux/config
# vim /etc/selinux/config
2、修改 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 - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
3、重启电脑查看 Selinux 状态,应该为关闭状态
$ getenforce
Disabled
外网是可以访问上去了,可是发现没法返回目录(使用ftp的主动模式,被动模式还是无法访问),也上传不了,因为selinux作怪了。
修改selinux:
执行以下命令查看状态:
[root@hyy ~]# getsebool -a | grep ftp
allow_ftpd_anon_write --> off # 允许匿名修改
ftpd_full_access --> off # 允许数据访问
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
tftp_home_dir --> off # 允许home目录
ftpd_connect_db --> off # 允许连接数据库
ftpd_use_passive_mode --> off # 警告
httpd_enable_ftp_server --> off # 允许 开启ftp服务
tftp_anon_write --> off # 允许匿名写
[root@hyy ~]#
执行上面命令,再返回的结果看到两行都是off,代表,没有开启外网的访问
[root@hyy ~]# setsebool -P allow_ftpd_full_access on
设置 -P永久 全访问 on 激活
[root@hyy ~]# setsebool -P ftp_home_dir on 目录访问
2 ssh只能远程登陆到普通用户,不能以root远程登陆
默认是不允许root用户登录SSH的,如果登陆结果就会如下:
用PiY登陆时,总提示:
login as: root
Using keyboard-interactive authentication.
Password:
Access denied 访问超时
这个时候需要编辑其配置文件,输入以下命令进行修改:
vim /etc/ssh/sshd_config 文件 /etc/ssh/sshd_config,不是 /etc/ssh/ssh_config
然后进行修改. 找到
#PasswordAuthentication no 修改为: PasswordAuthentication yes
这段的意思是,让SSH使用密码验证登陆. 找到
#PermitRootLogin no 修改为 PermitRootLogin yes
这段的意思是,让SSH准许root用户登录.一般来说,为了安全起见,这一段
还是不要允许的好.不过安全要求不高,可以这样做. 找到
#PermitEmptyPasswords no 修改为 PermitEmptyPasswords no
这段的意思是,允许空密码登录改为不
保存、重启
3 SSH能登录,ftp不能远程获取目录列表及修改文件
修改远程访问客户端 如editplus/xshell/filwzilla的FTP/SFTP选择sftp和活动状态、
一般不用操作
FTP服务1. 开启FTP服务步骤: 2 安装FTP服务包:#yum -y install vsftpd 3. 设置开机启动vsftpd ftp服务:# chkconfig vsftpd on 4. 开启FTP服务:# service vsftpd restartPS:需关闭selinux (setenforce 0)
SFTP服务
- #ssh –V 来查看openssh的版本,如果低于4.8p1,需要自行升级安装,
- 创建sftp组:#groupadd sftp
- 创建测试账户:#useradd -g sftp -s /bin/false testuser 修改密码:# passwd testuser
- 创建目录:#mkdir /opt/sftp #cd /opt/sftp; #mkdir testuser
- 修改测试账户HOME路径:# usermod -d /opt/sftp/testuser testuser
- 配置sshd_config :# vim /etc/ssh/sshd_config
- 注释掉:Subsystem sftp /usr/libexec/openssh/sftp-server
- 添加如下几行
- Subsystem sftp internal-sftp
- Match Group sftp
- ChrootDirectory /opt/sftp/%u
- ForceCommand internal-sftp
- AllowTcpForwarding no
- X11Forwarding no
- 设定Chroot目录权限:chown root:sftp /opt/sftp/testuser #chmod 755 /opt/sftp/testuser
- # mkdir /opt/sftp/testuser/upload
- # chown uplus:sftp /opt/sftp/testuser/upload
- # chmod 755 /opt/sftp/testuser/upload
- 重启sshd服务:# service sshd restart
httpd常规使用参考
上述只是简单的概念,便于理解,下面以httpd为例,做实际操作说明。
1)httpd启动时需要使用端口22 . 80、81、443等,需要开通权限
# 查看当前httpd的端口权限
[root@test /]# semanage port -l|grep http
http_cache_port_t tcp 3128, 8080, 8118, 11211, 10001-10010
http_cache_port_t udp 3130, 11211
http_port_t tcp 22 , 80, 443, 488, 8008, 8009, 8443
# 通常默认情况下22 ,80、443端口已经打开,现在需要添加对81端口的支持,使用以下命令
[root@test /]# semanage port -a -t http_port_t -p tcp 81 #与上边防火墙端口设置相同开放81端口
# 删除该端口
[root@test /]# semanage port -d -t http_port_t -p tcp 81
2)由于开启ssl需要使用到服务器证书,证书文件存放在特定的目录下(例如:/myweb/ssl),由于目录权限问题导致启动失败。
错误提示:SSLCertificateFile: file '/myweb/ssl/server.crt' does not exist or is empty
# 修改目录权限,使httpd进程(域)有权限访问证书相关的配置文件(注意:由于目录存在多层,需要对每层目录的权限进行设置,-R表示目录及其子目录、文件)
# 默认情况下httpd的安装路径/etc/httpd/的权限就是httpd_config_t
chcon -R -t httpd_config_t /myweb/ssl/
chcon -t httpd_config_t /myweb/
3)网站访问目录权限设置(httpd进程要求其访问的文件权限为httpd_sys_content_t)
# httpd默认安装的DocumentRoot指向的目录是/var/www/html,其权限默认已经设置为httpd_sys_content_t
# 如果修改DocumentRoot或设置了特定的Directory,则需要修改对应目录权限
# 例如:
chcon -t httpd_sys_content_t /myweb/www/
4)网站使用到第三方模块
chcon -t httpd_modules_t /your/module/xxx.so
5)如果需要启动第三方程序,则需要修改程序权限为httpd_exec_t
# 例如,在httpd中加入了modsecurity,安装路径在/etc/httpd/mlogc/
# 修改可执行程序/etc/httpd/mlogc/mlogc权限
chcon -t httpd_exec_t /etc/httpd/mlogc/mlogc