linux学习4

linux学习4

1、 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
~]# cp /etc/skel/ /home/tuser1
home]# getfacl tuser1/
# file: tuser1/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
home]# setfacl -m u::7,g::0,o::0 tuser1/
[root@ada-dog home]# getfacl tuser1/
# file: tuser1/
# owner: root
# group: root
user::rwx
group::—
other::—

2、 编辑/etc/group文件,添加组hadoop。
~]# echo “hadoop:x:1004:” >> /etc/group
3、 手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
~]# echo “hadoop:x:1003:1004::/home/hadoop:/bin/bash” >> /etc/passwd
4、 复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
home]# cp -rv /etc/skel/ /home/hadoop/
“/etc/skel/” -> “/home/hadoop/”
“/etc/skel/.mozilla” -> “/home/hadoop/.mozilla”
“/etc/skel/.mozilla/extensions” -> “/home/hadoop/.mozilla/extensions”
“/etc/skel/.mozilla/plugins” -> “/home/hadoop/.mozilla/plugins”
“/etc/skel/.bash_logout” -> “/home/hadoop/.bash_logout”
“/etc/skel/.bash_profile” -> “/home/hadoop/.bash_profile”
“/etc/skel/.bashrc” -> “/home/hadoop/.bashrc”
[root@ada-dog home]# getfacl hadoop/
# file: hadoop/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
home]# setfacl -m u::7,g::0,o::0 hadoop/
[root@ada-dog home]# getfacl hadoop/
# file: hadoop/
# owner: root
# group: root
user::rwx
group::—
other::—

5、 修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
home]# chown -Rv hadoop:hadoop /home/hadoop/
changed ownership of “/home/hadoop/.mozilla/extensions” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.mozilla/plugins” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.mozilla” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bash_logout” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bash_profile” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bashrc” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/” from root:root to hadoop:hadoop
home]# ls -al /home/hadoop/
总用量 12
drwx——. 3 hadoop hadoop 78 7月 10 15:41 .
drwxr-xr-x. 7 root root 73 7月 10 15:41 ..
-rw-r–r–. 1 hadoop hadoop 18 7月 10 15:41 .bash_logout
-rw-r–r–. 1 hadoop hadoop 193 7月 10 15:41 .bash_profile
-rw-r–r–. 1 hadoop hadoop 231 7月 10 15:41 .bashrc
drwxr-xr-x. 4 hadoop hadoop 39 7月 10 15:41 .mozilla
6、 显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
~]# grep -i ‘^s’ /proc/meminfo
SwapCached: 1456 kB
SwapTotal: 3145724 kB
SwapFree: 3112296 kB
Shmem: 2252 kB
Slab: 57744 kB
SReclaimable: 19724 kB
SUnreclaim: 38020 kB
~]# grep -E ‘^[sS]’ /proc/meminfo
SwapCached: 1652 kB
SwapTotal: 3145724 kB
SwapFree: 3111748 kB
Shmem: 2216 kB
Slab: 57168 kB
SReclaimable: 19724 kB
SUnreclaim: 37444 kB

7、 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
~]# cat /etc/passwd | grep -v “/sbin/nologin” | cut -d: -f1
root
sync
shutdown
halt
ada
fedora
centos
hadoop
8、 显示/etc/passwd文件中其默认shell为/bin/bash的用户;
~]# cat /etc/passwd | grep “/bin/bash” | cut -d: -f1
root
ada
fedora
centos
hadoop

9、 找出/etc/passwd文件中的一位数或两位数;
~]# grep “\<[[:digit:]]\{,2\}\>” /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
10、 显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
~]# grep “^[[:space:]]\+” /boot/grub/grub.conf
dfsgs
safa
gsgsg
wsd
sdfdse444
esg
fsgr\
11、 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
~]# grep “^#[[:space:]]\+[^[:space:]]\+” /etc/rc.d/rc.sysinit
# It receives polydir path as $1, the instance path as $2,
# a flag whether the instance dir was newly created (0 – no, 1 – yes) in $3,
# and user name in $4.
# The following section will copy the contents of /etc/skel if this is a
# newly created home directory.

12、 打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
~]# netstat -tan | grep “LISTEN[[:space:]]\+”
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
tcp6 0 0 ::1:6010 :::* LISTEN
tcp6 0 0 ::1:6011 :::* LISTEN

13、 添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
~]# useradd bash
~]# useradd testbash
~]# useradd basher
~]# useradd -s /sbin/nologin nologin
~]# grep “^\([^:]\+\>\).*\1$” /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:501:501::/home/bash:/bin/bash
nologin:x:504:504::/home/nologin:/sbin/nologin

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/102917

(0)
ヤ灬兵兵ヤ灬兵兵
上一篇 2018-07-14
下一篇 2018-07-14

相关推荐

  • liniux课程第一周总结

    第一天课程内容 MBR分区类型:主分区:1-4,一块硬盘最多4个主分区,不可以分小区,可以用来启动操作系统(系统分区),直接建文件系统,存放数据扩展分区:一块硬盘最多一个扩展分区,可以没有,加主分区最多4个,不能创建文件系统,可以再划分更小的分区(即逻辑分区)逻辑驱动器(分区):可以创建文件系统,存放数据 系统分区:启动操作系统的分区启动分区:安装操作系统的…

    Linux笔记 2018-04-01
  • 统计linux入门到shell脚本之间的基础练习题。

    答案都由本人奇特思路所创,如有错误,请在下面评论,好及时改正!

    Linux笔记 2018-04-15
  • ansible httpd

    卸载服务ansible all -m shell -a ‘yum -y remove nginx’ 检查用户 组 uid gidansible all -m shell -a ‘getent passwd nginx’ansible all -m shell -a ‘getent group ngi…

    Linux笔记 2018-07-23
  • Linux 的不同的发行版区别和联系

    Linux 的不同的发行版区别和联系   Linux,最早由Linus Benedict Torvalds在1991年开始编写。在这之前,Richard Stallman创建了Free Software Foundation(FSF)组织以及GNU项目,并不断的编写创建GNU程序(此类程序的许可方式均为GPL: General Public Lic…

    2018-08-04
  • 创建配置格式文件的格式 C语言源代码安装三步骤 yum

    创建配置文件的格式: [base] name= centos cdrom mirrorlist=file:///root/baselist gpgkey=file:///mnt/cdrom/rpm-gpg-key-centos-7     [epel] name=epel baseurl=https://mirrors aliyun.co…

    Linux笔记 2018-04-22

评论列表(1条)

  • 马哥教育
    马哥教育 2018-07-18 21:58

    第一题有问题, 需要注意下,另外,能注意下排版最好。