首页 > 其他分享 >实验4

实验4

时间:2024-02-24 22:25:47浏览次数:30  
标签:kB sbin set -- nologin 实验 root

练习

1.当用户docker对/testdir 目录无执行权限时,意味着无法做哪些操作?

无法进入该目录,即不能使用cd /testdir命令切换到该目录。
如果试图访问/testdir下的文件或子目录,即使这些文件有合适的权限,由于用户不能搜索目录内容,所以也无法直接通过相对路径来访问。

2.当用户mongodb对/testdir 目录无读权限时,意味着无法做哪些操作?

无法查看/testdir目录下的文件和子目录列表,即不能使用ls /testdir命令列出目录内容。
因为没有目录的读权限,所以即使目录内的某个文件对其有写或执行权限,用户mongodb也无法通过相对路径找到并访问这些文件。

3.当用户redis 对/testdir 目录无写权限时,该目录下的只读文件file1是否可修改和删除?

当用户redis对/testdir目录无写(w)权限时,该目录下的只读文件file1不可修改。但删除文件的行为并不受文件所在目录的写权限影响,而是取决于用户对文件本身的权限。如果redis用户对file1只有读权限而无写权限和执行权限,则无法修改或删除该文件。

4.当用户zabbix对/testdir 目录有写和执行权限时,该目录下的只读文件file1是否可修改和删除?

用户zabbix对/testdir目录有写(w)和执行(x)权限时,对于目录下的只读文件file1,即使目录拥有足够的权限,如果file1设置为只读,zabbix用户仍然无法修改文件内容,因为需要文件自身的写权限。但是,如果zabbix用户对该文件有写权限或者属于文件所有者并且具有sudo权限,那么理论上是可以更改其权限后再进行修改的。至于删除文件,同样需要对文件本身具有写权限或属主权限,目录的权限并不能决定能否删除文件。

5.复制/etc/fstab文件到/var/tmp下,设置文件所有者为tomcat读写权限,所属组为apps组有读写
权限,其他人无权限

要复制 /etc/fstab 文件到 /var/tmp 并设置相应权限,可以这样操作:

Bash
sudo cp /etc/fstab /var/tmp/
sudo chown tomcat:apps /var/tmp/fstab
sudo chmod 660 /var/tmp/fstab
这里的 chmod 660 指令将文件权限设置为:所有者(tomcat)具有读写权限(6),所属组(apps)具有读写权限(6),其他人没有任何权限(0)。


6.误删除了用户git的家目录,请重建并恢复该用户家目录及相应的权限属性

# 创建用户git的家目录,并设置适当的权限
sudo mkdir /home/git
sudo chown git:git /home/git
sudo chmod 700 /home/git

# 如果之前备份过/home/git的内容,还原备份
sudo rsync -aP /path/to/backup/home/git/ /home/git/

# 或者根据实际情况重新配置家目录内容,例如创建默认文件等
sudo cp -rp /etc/skel/. /home/git/

# 如果需要恢复特定的文件权限,可以根据之前记录的权限进行设置
# 对于每个文件或目录分别执行chown和chmod命令
请注意,如果你没有事先备份git用户的家目录,那么上述过程将只能创建一个空的家目录,并且可能需要手动重新配置相关文件和环境设置。若已有的数据未备份,则无法恢复。

练习

1、找出ifconfig “网卡名” 命令结果中本机的IPv4地址

ifconfig ens160 | grep 'inet ' | awk '{print $2}' | cut -d':' -f2

2、查出分区空间使用率的最大百分比值

df | tr -s ' ' '%' | cut -d '%' -f 5 | sort -nr | head -n 1

3、查出用户UID最大值的用户名、UID及shell类型

awk -F: 'BEGIN{max=0} $3>max{u=$1; max=$3} END{print u, max, $7}' /etc/passwd

4、查出/tmp的权限,以数字方式显示

stat -c '%a' /tmp

5、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序

netstat -an | grep 'ESTABLISHED' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr

1、显示/proc/meminfo文件中以大小s开头的行(要求:使用六种方法)

[13:58:43 root@localhost ~][#awk '/^[0-9]+(.[0-9]+)?[kKmMgGtTpPeE]?[sS]/ {print}' /proc/meminfo
[13:58:52 root@localhost ~][#grep -i "^[^[:space:]]*s" /proc/meminfo | cut -d' ' -f1
Buffers:
SwapCached:
SwapTotal:
SwapFree:
Zswap:
Zswapped:
AnonPages:
Shmem:
Slab:
SReclaimable:
SUnreclaim:
KernelStack:
PageTables:
SecPageTables:
NFS_Unstable:
Committed_AS:
VmallocUsed:
AnonHugePages:
ShmemHugePages:
ShmemPmdMapped:
FileHugePages:
HugePages_Total:
HugePages_Free:
HugePages_Rsvd:
HugePages_Surp:
Hugepagesize:










方法一

[14:00:26 root@localhost ~][#(head -n 100 /proc/meminfo; tail -n +101 /proc/meminfo) | grep '^[Ss]'
SwapCached:            0 kB
SwapTotal:       2105340 kB
SwapFree:        2105340 kB
Shmem:             13268 kB
Slab:             119644 kB
SReclaimable:      45084 kB
SUnreclaim:        74560 kB
SecPageTables:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB






方法二 
注意此方法会一直查找下去,所以如果ctrl+c无法退出的话,那就按ctrl+z


[14:01:00 root@localhost ~][#less +'/^[Ss]' /proc/meminfo



















SwapCached:            0 kB
Active:           137760 kB
Inactive:         870436 kB
Active(anon):       2624 kB
Inactive(anon):   469452 kB
Active(file):     135136 kB
Inactive(file):   400984 kB
Unevictable:          16 kB
Mlocked:              16 kB
SwapTotal:       2105340 kB
SwapFree:        2105340 kB
Zswap:                 0 kB
Zswapped:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        454760 kB
Mapped:           186652 kB
Shmem:             13268 kB
KReclaimable:      45084 kB
Slab:             119712 kB
SReclaimable:      45084 kB
SUnreclaim:        74628 kB
KernelStack:        8696 kB
PageTables:        10152 kB
SecPageTables:         0 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2992200 kB
Committed_AS:    2032596 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       59412 kB
VmallocChunk:          0 kB
Percpu:            59392 kB
HardwareCorrupted:     0 kB
AnonHugePages:    235520 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      180096 kB
DirectMap2M:     1916928 kB
DirectMap1G:           0 kB












方法三



[14:05:35 root@localhost ~][#cat /proc/meminfo | grep '^[Ss]'
SwapCached:            0 kB
SwapTotal:       2105340 kB
SwapFree:        2105340 kB
Shmem:             13260 kB
Slab:             119676 kB
SReclaimable:      45500 kB
SUnreclaim:        74176 kB
SecPageTables:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB

2、显示/etc/passwd文件中不以/bin/bash结尾的行

[root@centos7 ~]# grep -v '/bin/bash$' /etc/passwd
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
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
libstoragemgmt:x:998:997:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin
saslauth:x:996:76:Saslauthd user:/run/saslauthd:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
chrony:x:995:993::/var/lib/chrony:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
geoclue:x:994:991:User for geoclue:/var/lib/geoclue:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:992:987::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
bash:x:1001:1001::/home/bash:/sbin/bash
testbash:x:1002:1002::/home/testbash:/sbin/bash
basher:x:1003:1003::/home/basher:/sbin/bash
sh:x:1004:1004::/home/sh:/sbin/bash
nologin:x:1005:1005::/home/nologin:/sbin/nologin








3、显示用户rpc默认的shell程序

[root@centos7 ~]# grep rpc /etc/passwd | cut -d: -f7
/sbin/nologin
/sbin/nologin


[root@centos7 ~]# grep '^rpc:' /etc/passwd | cut -d: -f7
/sbin/nologin

4、找出/etc/passwd中的两位或三位数

[root@centos7 ~]# grep -o '[0-9]\{2,3\}' /etc/passwd
12
11
12
100
14
50
99
99
192
192
81
81
999
998
173
173
998
997
32
32
997
996
996
76
172
172
995
993
107
107
59
59
113
113
994
991
29
29
655
34
655
34
75
75
993
990
171
171
42
42
992
987
74
74
70
70
89
89
38
38
72
72
100
100
100
100
100
100
100
100
100
100
100
100




[13:54:45 root@localhost ~][#grep -oE '[0-9]{2,3}' /etc/passwd
12
11
12
100
14
50
655
34
655
34
999
997
81
81
998
996
70
70
172
172
997
993
996
992
990
990
989
989
59
59
988
987
987
986
986
985
985
984
984
983
983
982
982
981
42
42
981
980
74
74
980
979
979
978
72
72
100
100
89
89
100
100
100
100
100
100
100
100

5、显示CentOS7的/etc/grub2.cfg文件中,至少以一个空白字符开头的且后面有非空白字符的行


[root@centos7 ~]# grep '^[[:space:]]\+[^[:space:]]' /etc/grub2.cfg
  load_env
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
   set default="${saved_entry}"
  menuentry_id_option="--id"
  menuentry_id_option=""
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
  set timeout_style=menu
  set timeout=5
  set timeout=5
  source ${prefix}/user.cfg
  if [ -n "${GRUB2_PASSWORD}" ]; then
    set superusers="root"
    export superusers
    password_pbkdf2 root ${GRUB2_PASSWORD}
  fi
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_msdos
	insmod xfs
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  4c6d4e1d-bfc8-48a4-a48c-9247095fec80
	else
	  search --no-floppy --fs-uuid --set=root 4c6d4e1d-bfc8-48a4-a48c-9247095fec80
	fi
	linux16 /vmlinuz-3.10.0-693.el7.x86_64 root=UUID=e5f25cac-f6e2-4533-8253-ab83965d54fa ro rhgb quiet LANG=en_US.UTF-8
	initrd16 /initramfs-3.10.0-693.el7.x86_64.img
	load_video
	insmod gzio
	insmod part_msdos
	insmod xfs
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  4c6d4e1d-bfc8-48a4-a48c-9247095fec80
	else
	  search --no-floppy --fs-uuid --set=root 4c6d4e1d-bfc8-48a4-a48c-9247095fec80
	fi
	linux16 /vmlinuz-0-rescue-1ba5fcb6a5ba4c61a4599eea3f57608c root=UUID=e5f25cac-f6e2-4533-8253-ab83965d54fa ro rhgb quiet
	initrd16 /initramfs-0-rescue-1ba5fcb6a5ba4c61a4599eea3f57608c.img
  source ${config_directory}/custom.cfg
  source $prefix/custom.cfg;














[13:53:17 root@localhost ~][#grep '^\s\+[^[:space:]]' /etc/grub2.cfg
  load_env -f ${config_directory}/grubenv
  load_env
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
   set default="${saved_entry}"
  menuentry_id_option="--id"
  menuentry_id_option=""
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
  set timeout_style=menu
  set timeout=5
  set timeout=5
  source ${prefix}/user.cfg
  if [ -n "${GRUB2_PASSWORD}" ]; then
    set superusers="root"
    export superusers
    password_pbkdf2 root ${GRUB2_PASSWORD}
  fi
  # if countdown has ended, choose to boot rollback deployment,
  # i.e. default=1 on OSTree-based systems.
  if  [ "${boot_counter}" = "0" -o "${boot_counter}" = "-1" ]; then
    set default=1
    set boot_counter=-1
  # otherwise decrement boot_counter
  else
    decrement boot_counter
  fi
  save_env boot_counter
  search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1'  fb99d21e-3f1c-4194-9c68-f71f2740591d
  search --no-floppy --fs-uuid --set=root fb99d21e-3f1c-4194-9c68-f71f2740591d
  search --no-floppy --fs-uuid --set=boot --hint='hd0,msdos1'  fb99d21e-3f1c-4194-9c68-f71f2740591d
  search --no-floppy --fs-uuid --set=boot fb99d21e-3f1c-4194-9c68-f71f2740591d
  set kernelopts="root=/dev/mapper/rl-root ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rl-swap rd.lvm.lv=rl/root rd.lvm.lv=rl/swap rhgb quiet "
  set menu_hide_ok=1
  set menu_hide_ok=0 
  set boot_indeterminate=0
  set boot_indeterminate=2
  if [ "${menu_show_once}" ]; then
    unset menu_show_once
    save_env menu_show_once
    set timeout_style=menu
    set timeout=60
  elif [ "${menu_auto_hide}" -a "${menu_hide_ok}" = "1" ]; then
    set orig_timeout_style=${timeout_style}
    set orig_timeout=${timeout}
    if [ "${fastboot}" = "1" ]; then
      # timeout_style=menu + timeout=0 avoids the countdown code keypress check
      set timeout_style=menu
      set timeout=0
    else
      set timeout_style=hidden
      set timeout=1
    fi
  fi
  if [ "${menu_show_once_timeout}" ]; then
    set timeout_style=menu
    set timeout="${menu_show_once_timeout}"
    unset menu_show_once_timeout
    save_env menu_show_once_timeout
  fi
	menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
		fwsetup
	}
  source ${config_directory}/custom.cfg
  source $prefix/custom.cfg

6、找出“netstat -tan”命令结果中以LISTEN后跟任意多个空白字符结尾的行

[13:52:50 root@localhost ~][#netstat -tan | grep 'LISTEN\s*$'
tcp        0      0 127.0.0.1:631           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:6010          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN     
tcp6       0      0 ::1:6011                :::*                    LISTEN     
tcp6       0      0 ::1:6010                :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN    

7、显示CentOS7上所有UID小于1000以内的用户名和UID

awk -F: '$3 < 1000 {print $1 "\t" $3}' /etc/passwd

8、添加用户bash、testbash、basher、sh、nologin(其shell为/sbin/nologin),找出/etc/passwd用户

名和shell同名的行

首先添加用户:

bash
useradd bash -s /sbin/bash  
useradd testbash -s /sbin/bash  
useradd basher -s /sbin/bash  
useradd sh -s /sbin/bash  
useradd nologin -s /sbin/nologin
然后查找同名用户和shell:

bash
grep '^\([^:]:[^:]\)\:\(.*\)\:\(.*\):\4:' /etc/passwd

9、利用df和grep,取出磁盘各分区利用率,并从大到小排序

df | grep -oP '\d+%' | sort -nr

标签:kB,sbin,set,--,nologin,实验,root
From: https://www.cnblogs.com/nwq1101/p/18031729

相关文章

  • 实验室与排课管理系统
    适用于校园与科研单位主要技术栈Java8Maven3.6.3MySQL5.7Python3.8SpringBoot框架Vue2  项目地址:https://github.com/BennettMa23 说明手册默认用户,可在系统的用户管理自行增加管理员:用户名:admin密码:admin老师:用户名:teacher密码:admin学生......
  • 实验3
    (1)如何创建/testdir/dir1/x,/testdir/dir1/y,/testdir/dir1/x/a,/testdir/dir1/x/b,/testdir/dir1/y/a,/testdir/dir1/y/bmkdir-p/testdir/dir1/{x,y}/{a,b}touch/testdir/dir1/{x,y}/{a,b}(2)如何创建/testdir/dir2/x,/testdir/dir2/y,/testdir/dir2/x/a,/test......
  • 实验2
    如何设置Ubuntu的远程连接root1.切换成rootsudo-i1.5设置个root密码passwd2.进入nano/etc/ssh/sshd_confignano/etc/ssh/sshd_config3.修改这个位置PermitRootloginyes4.保存ctrl+x5.确定y6.回车enter7.效果结果:Ubuntu2004和Ubuntu2204都成......
  • 实验1
    vmnet1192.168.10.0vmnet810.0.0.0安装rocky9、centos6/7/8,Ubuntu1804/20.04/22.04用虚拟机安装1.安装**CentOS1.1针对CentOS7/6/8创建虚拟机环境2.安装包Ubuntu1804/2004/22043.安装rocky密码自己......
  • spark实验七 SparkMLlib
    1.数据导入从文件中导入数据,并转化为DataFrame。2.进行主成分分析(PCA)对6个连续型的数值型变量进行主成分分析。PCA(主成分分析)是通过正交变换把一组相关变量的观测值转化成一组线性无关的变量值,即主成分的一种方法。PCA通过使用主成分把特征向量投影到低维空间,实现对特征......
  • spark实验六SparkStreaming
    1.安装FlumeFlume是Cloudera提供的一个分布式、可靠、可用的系统,它能够将不同数据源的海量日志数据进行高效收集、聚合、移动,最后存储到一个中心化数据存储系统中。Flume的核心是把数据从数据源收集过来,再送到目的地。请到Flume官网下载Flume1.7.0安装文件,下载地址如......
  • mpsoc嵌入式vitis开发—EMIO LED实验
    前言vitis版本:Vitis2023.2由于Vitis版本更新,很多API发生变化,学习原子哥的教程时很多代码对于不上,所以自己重新写一遍,并记录下自己踩过的坑,方便以后查看。这里直接给出代码,其他的流程参考原子哥的《2_DFZU2EG_4EVMPSoC之嵌入式Vitis开发指南_V1.0.pdf》代码采用CodeGeeX-AM......
  • BOSHIDA 高精度DC电源模块在科学实验中的作用与价值
    BOSHIDA高精度DC电源模块在科学实验中的作用与价值BOSHIDA高精度DC电源模块在科学实验中具有重要的作用和价值。下面列举了几个方面: 1.稳定的电源供电:科学实验中通常需要稳定的电源供电,以确保实验结果的准确性和可重复性。高精度DC电源模块能够提供稳定的直流电压输出,有效......
  • spark实验五Spark SQL
    1.SparkSQL基本操作将下列JSON格式数据复制到Linux系统中,并保存命名为employee.json。{"id":1,"name":"Ella","age":36}{"id":2,"name":"Bob","age":29}{"id":3,"name"......
  • mpsoc嵌入式vitis开发—AXI GPIO中断实验
    前言vitis版本:Vitis2023.2由于Vitis版本更新,很多API发生变化,学习原子哥的教程时很多代码对于不上,所以自己重新写一遍,并记录下自己踩过的坑,方便以后查看。这里直接给出代码,其他的流程参考原子哥的《2_DFZU2EG_4EVMPSoC之嵌入式Vitis开发指南_V1.0.pdf》代码#include"sleep.h......