linux shell 逻辑运算符、逻辑表达式详解

一、逻辑运算符

逻辑卷标 表示意思
1. 关于档案与目录的侦测逻辑卷标!
-f 常用!侦测『档案』是否存在 eg: if [ -f filename ]
-d 常用!侦测『目录』是否存在
-b 侦测是否为一个『 block 档案』
-c 侦测是否为一个『 character 档案』
-S 侦测是否为一个『 socket 标签档案』
-L 侦测是否为一个『 symbolic link 的档案』
-e 侦测『某个东西』是否存在!
2. 关于程序的逻辑卷标!
-G 侦测是否由 GID 所执行的程序所拥有
-O 侦测是否由 UID 所执行的程序所拥有
-p 侦测是否为程序间传送信息的 name pipe 或是 FIFO (老实说,这个不太懂!)
3. 关于档案的属性侦测!
-r 侦测是否为可读的属性
-w 侦测是否为可以写入的属性
-x 侦测是否为可执行的属性
-s 侦测是否为『非空白档案』
-u 侦测是否具有『 SUID 』的属性
-g 侦测是否具有『 SGID 』的属性
-k 侦测是否具有『 sticky bit 』的属性
4. 两个档案之间的判断与比较 ;例如[ test file1 -nt file2 ]
-nt 第一个档案比第二个档案新
-ot 第一个档案比第二个档案旧
-ef 第一个档案与第二个档案为同一个档案( link 之类的档案)
5. 逻辑的『和(and)』『或(or)』
&& 逻辑的 AND 的意思
|| 逻辑的 OR 的意思

继续阅读“linux shell 逻辑运算符、逻辑表达式详解”

vsftpd:500 OOPS: vsftpd: refusing to run with writable root inside chroot ()错误的解决方法

当我们限定了用户不能跳出其主目录之后,使用该用户登录FTP时往往会遇到这个错误:

500 OOPS: vsftpd: refusing to run with writable root inside chroot ()

这个问题发生在最新的这是由于下面的更新造成的

– Add stronger checks for the configuration error of running with a writeable root directory inside a chroot(). This may bite people who carelessly turned on chroot_local_user but such

从2.3.5之后,vsftpd增强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了!如果检查发现还有写权限,就会报该错误。

要修复这个错误,可以用命令chmod a-w /home/user去除用户主目录的写权限,注意把目录替换成你自己的。或者你可以在vsftpd的配置文件中增加下列两项中的一项:

#vi /etc/vsftpd.conf

allow_writeable_chroot=YES

CentOS7安装设置FTP

一.安装FTP

1.检测是否安装了FTP:

[root@localhost ~]# rpm -q vsftpd
如果安装了会显示版本信息:
[root@localhost ~]# vsftpd-2.0.5-16.el5_5.1
否则显示:
[root@localhost ~]# package vsftpd is not installed

2. 安装FTP

[root@localhost ~]# yum install vsftpd

2.1 完成FTP安装后,将/ETC/VSFTPD/USER_LIST文件和/ETC/VSFTPD/FTPUSERS文件中的ROOT这一行用#注释掉

# root

2.2 执行以下命令

#setsebool -P ftpd_disable_trans=1
修改/etc/vsftpd/vsftpd.conf,在最后一行处添加local_root=/

2.3 重启FTP进程

#service vsftpd restart
**注:每次修改过ftp相关的配置文件,都需要重启ftp进程来生效。 ftp服务器就可以使用了。**

二. 配置FTP

1.创建一个账号为test的账户:

#mkdir /tmp/test //首先创建好目录
#adduser -d /tmp/test -g ftp -s /sbin/nologin test
//-s /sbin/nologin是让其不能登陆系统,-d是指定用户目录为/opt/srsman,即该账户只能登陆ftp,却不能用做登陆系统用。

1.1 为TEST设置密码

#passwd test
Changing password for user beinan.//接下来会出现让你设置新的密码
New password:
Retype new password:
passwd: all authentication tokens updated successfully

2. 限制用户目录,不得改变目录到上级

2.1 修改/ETC/VSFTPD/VSFTPD.CONF

将这两行
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd.chroot_list
注释去掉
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

2.2 新增一个文件: /ETC/VSFTPD/CHROOT_LIST

内容写需要限制的用户名:
test
重新启动vsftpd
#service vsftpd restart

3. 设置开机启动

(1)找到/etc/rc.local文件
(2)打开该文件,在最后一行添加:service vsftpd start
(3)保存,退出

4. 用FTP客户端快速连接

在centos7上搭建Apache+mariadb+php7

  • 安装mariadb

# yum install mariadb-server mariadb

啟動及設定開機自動執行 MariaDB:

# systemctl start mariadb
# systemctl enable mariadb

安装Apache

# yum install httpd

跟著回答 “y” 後便會完成安裝, 然後輸入以下指令啟動及設定 Apache 開機自動執行:

# systemctl start httpd
# systemctl enable httpd

安裝 PHP 7

下载php7包到/usr/local/src/ 目录并解压

安装扩展包

# yum install gcc libxml2-devel pkgconfig openssl-devel bzip2-devel libpng-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel httpd-devel

进入php7解压包

# ./configure \
–prefix=/usr/local/php7/usr \
–with-config-file-path=/usr/local/php7/usr/etc \
–enable-mbstring \
–enable-zip \
–enable-bcmath \
–enable-pcntl \
–enable-ftp \
–enable-exif \
–enable-calendar \
–enable-sysvmsg \
–enable-sysvsem \
–enable-sysvshm \
–enable-wddx \
–with-curl \
–with-mcrypt \
–with-iconv \
–with-gmp \
–with-pspell \
–with-gd \
–with-jpeg-dir=/usr \
–with-png-dir=/usr \
–with-zlib-dir=/usr \
–with-xpm-dir=/usr \
–with-freetype-dir=/usr \
–enable-gd-native-ttf \
–enable-gd-jis-conv \
–with-openssl \
–with-pdo-mysql=/usr \
–with-gettext=/usr \
–with-zlib=/usr \
–with-bz2=/usr \
–with-recode=/usr \
–with-mysqli=/usr/bin/mysql_config \
–with-apxs2

然后

#make

#make test

#make install

复制 php.ini-development 文件到 /usr/local/lib 保存为 php.ini

编辑Apache配置文件 /etc/httpd/conf/httpd.conf  加入以下内容

LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

保存后重启Apache

最小化安装centos7后上网设置

在虚拟机中以最小化方式安装centos7,后无法上网,因为centos7默认网卡未激活。

可以设置

文件 /etc/sysconfig/network-scripts/ifcfg-enp0s3

将 ONBOOT=no 改为 ONBOOT=yes

保存后重启网卡: service network restart

此时就可以上网了。

因为是最小化安装,此时ifconfig命令不能用,可用

命令:ip addr  查看分配网卡情况。

联网后可运行命令:

yum install net-tools

来安装ifconfig功能

此时virtualbox采用的网络连接方式为:网络地址转化(NAT)方式