1、判断UID是否大于等于500,如果为真就显示为普通用户,如果为假就显示为系统或管理用户
#!/bin/bash
if [ $# -lt 1 ];then
echo "Usage: testuser.sh [username..]"
exit 1
else
for i in `seq $#`;do
uid=`id ${!i} | cut -d' ' -f1| grep -o [[:digit:]]*`
if [ $uid -ge 500 ];then
echo "${!i} is a normal user."
else
echo "${!i} is a system user."
fi
done
fi
[root@localhost data]# ./testuser.sh mysql root wang
mysql is a system user.
root is a system user.
wang is a normal user.
2、显示用户id为奇数的用户
#!/bin/bash
while read line;do
uid=`echo $line | awk -F: '{print $3}' `
if [ $[$uid%2] -eq 0 ];then
continue
else
echo $line| awk -F: '{print $1}'
fi
done < /etc/passwd
[root@localhost data]# bash checkuser.sh
bin
adm
sync
halt
operator
gopher
nobody
dbus
usbmuxd
rtkit
vcsa
abrt
rpcuser
postfix
pulse
user1
named
mysql
3、统计web服务访问日志中的ip访问量
[root@centos7 bin]# vim access.sh
#!/bin/bash
read -p "Please input the path of accesslogfile: " logfile
awk '{print $1}' $logfile | sort -rn | uniq -c | sort -rn | head -10
[root@centos7 bin]# bash access.sh
Please input the path of accesslogfile: access.log
40 172.18.254.70
35 172.18.251.202
10 172.18.253.55
3 172.18.16.1
1 172.18.252.194
1 172.18.12.10
4、简述加密类型以及数据加密解密过程
加密根据其加密算法的不同一般分为两类,对称加密和非对称加密
5、搭建私有CA并实现证书颁发
[ CA_default ]
dir = /etc/pki/CA # Where everything is kept
certs = $dir/certs # Where the issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # database index file.
#unique_subject = no # Set to 'no' to allow creation of
# several ctificates with same subject.
new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate
serial = $dir/serial # The current serial number
crlnumber = $dir/crlnumber # the current crl number
# must be commented out to leave a V1 CRL
crl = $dir/crl.pem # The current CRL
private_key = $dir/private/cakey.pem# The private key
cd /etc/pki/CA/
(umask 066; openssl genrsa -out private/cakey.pem 2048) #生成私钥
touch index.txt #创建数据库索引文件
echo 01 > serial #初始化数据库证书编号
cat serial
openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 3650 -out /etc/pki/CA/cacert.pem #生成自签名证书
[root@localhost CA]# tree ./
./
├── cacert.pem #自签名证书
├── certs
│ └── test.csr #证书申请文件
├── crl
├── crlnumber #证书吊销的下一个编号
├── crlnumber.old #最后一个吊销证书的编号
├── crl.pem #吊销证书列表
├── index.txt #证书索引数据库文件
├── index.txt.attr
├── index.txt.attr.old
├── index.txt.old
├── newcerts
│ └── 01.pem #已颁发的证书
├── private
│ └── cakey.pem #私钥
├── serial #下一个证书的编号
└── serial.old
4 directories, 13 files
(umask 066; openssl genrsa –out /data/test.key 2048)
openssl req -new -key /data/test.key -out /data/test.csr
openssl ca -in /tmp/test.csr –out /etc/pki/CA/certs/test.crt -days 100
openssl x509 -in /etc/pki/CA/certs/test/crt -noout -text
openssl ca -status SERIAL
openssl x509 -in /PATH/FROM/CERT_FILE -noout -serial -subject
openssl ca -revoke /etc/pki/CA/newcerts/SERIAL.pem
echo 01 > /etc/pki/CA/crlnumber
openssl ca -gencrl -out /etc/pki/CA/crl.pem
openssl crl -in /etc/pki/CA/crl.pem -noout -text