实验环境: 宿主机为win11 Vmware workstaion 17 目标机的OS: Ubuntu 2004 网络:NAT 获取地址:192.168.248.131/24 DNS,DHCP:192.168.248.2 |
第一章ppt的命令操作(部分) S1、执行whoami、who、w命令 root@testhost01:/home/test/Desktop# whoami root root@testhost01:/home/test/Desktop# who test :0 2024-03-06 16:27 (:0) root@testhost01:/home/test/Desktop# w 16:49:03 up 51 min, 1 user, load average: 0.14, 0.21, 0.34 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT test :0 :0 16:27 ?xdm? 4:18 0.01s /usr/libexec/gd root@testhost01:/home/test/Desktop# test@testhost01:~/Desktop$ w 16:49:28 up 52 min, 1 user, load average: 0.09, 0.20, 0.33 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT test :0 :0 16:27 ?xdm? 4:20 0.01s /usr/libexec/gd test@testhost01:~/Desktop$ who test :0 2024-03-06 16:27 (:0) test@testhost01:~/Desktop$ whoami test S2、执行whatis、whereis、which、man、lsusb、uname、arch命令 test@testhost01:~/Desktop$ whatis ls ls (1) - list directory contents test@testhost01:~/Desktop$ whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz test@testhost01:~/Desktop$ which ls /usr/bin/ls test@testhost01:~/Desktop$ man passwd test@testhost01:~/Desktop$ man -k selinux pam_selinux (7) - PAM module to set the default security context pam_sepermit (8) - PAM module to allow/deny login depending on SELinux en... semanage.conf (5) - global configuration file for the SELinux Management l... test@testhost01:~/Desktop$ root@testhost01:/home/test/Desktop# lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub root@testhost01:/home/test/Desktop# free -m total used free shared buff/cache available Mem: 7902 1417 4576 2 1908 6203 Swap: 0 0 0 root@testhost01:/home/test/Desktop# test@testhost01:~/Desktop$ uname -r 5.15.0-91-generic test@testhost01:~/Desktop$ arch x86_64 test@testhost01:~/Desktop$ S3、执行parted、fdisk命令 root@testhost01:/home/test/Desktop# parted -l Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 64.4GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 540MB 538MB fat32 EFI System Partition boot, esp 3 540MB 64.4GB 63.9GB ext4 root@testhost01:/home/test/Desktop# fdisk -l Disk /dev/loop0: 55.66 MiB, 58368000 bytes, 114000 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/loop1: 55.66 MiB, 58363904 bytes, 113992 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/loop2: 4 KiB, 4096 bytes, 8 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes |
二、复习常用命令: telnet、useradd、newusers、userdel、usermod、groupadd、groupdel、groupmod、su S1、查看/etc/passwd和/etc/shadow文件 root@testhost01:/home/test/Desktop# cat /etc/passwd … colord:x:120:126:colord colour management daemon,,,:/var/lib/colord:/usr/sbin/nologin sssd:x:121:127:SSSD system user,,,:/var/lib/sss:/usr/sbin/nologin geoclue:x:122:128::/var/lib/geoclue:/usr/sbin/nologin pulse:x:123:129:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin hplip:x:124:7:HPLIP system user,,,:/run/hplip:/bin/false gnome-initial-setup:x:125:65534::/run/gnome-initial-setup/:/bin/false gdm:x:126:131:Gnome Display Manager:/var/lib/gdm3:/bin/false test:x:1000:1000:test,,,:/home/test:/bin/bash systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin sshd:x:127:65534::/run/sshd:/usr/sbin/nologin xrdp:x:128:135::/run/xrdp:/usr/sbin/nologin nginx:x:129:136:nginx user,,,:/nonexistent:/bin/false lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false fwupd-refresh:x:130:137:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologin root@testhost01:/home/test/Desktop# cat /etc/shadow … … sssd:*:18557:0:99999:7::: geoclue:*:18557:0:99999:7::: pulse:*:18557:0:99999:7::: hplip:*:18557:0:99999:7::: gnome-initial-setup:*:18557:0:99999:7::: gdm:*:18557:0:99999:7::: test:$6$xBcb08zuERidUKrQ$qD5fD1.Q0G2b2qbZCXsr62UEgdgsIhGCeU9yAKNTT9kOip.Zi0apPzJxwrQOssVhvaFCBCj6AnTwOyXq8W7f7.:18774:0:99999:7::: systemd-coredump:!*:18774:::::: sshd:*:18775:0:99999:7::: xrdp:!:19013:0:99999:7::: nginx:!:19212:0:99999:7::: lxd:!:19570:::::: fwupd-refresh:*:19570:0:99999:7::: root@testhost01:/home/test/Desktop# S2、使用useradd、passwd命令 root@testhost01:/home/test/Desktop# useradd dx1a root@testhost01:/home/test/Desktop# cat /etc/passwd … nginx:x:129:136:nginx user,,,:/nonexistent:/bin/false lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false fwupd-refresh:x:130:137:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologin dx1a:x:1001:1001::/home/dx1a:/bin/sh root@testhost01:/home/test/Desktop# cat /etc/shadow … nginx:!:19212:0:99999:7::: lxd:!:19570:::::: fwupd-refresh:*:19570:0:99999:7::: dx1a:!:19788:0:99999:7::: test@testhost01:~/Desktop$ passwd dx1a passwd: You may not view or modify password information for dx1a. test@testhost01:~/Desktop$ su root Password: root@testhost01:/home/test/Desktop# passwd dx1a New password: 输入了1qaz@WSX Retype new password: passwd: password updated successfully root@testhost01:/home/test/Desktop# cat /etc/shadow nginx:!:19212:0:99999:7::: lxd:!:19570:::::: fwupd-refresh:*:19570:0:99999:7::: dx1a:$6$9m9rb7.8ivQHQrSA$zrMGNhdRGxALrIP6fDAJGTGMe9c1UE0NAUb.q3lLUMrivurbk/tvjPd5rZN9IKEBu6yjVXpX4qKGloWfSjB9E.:19789:0:99999:7::: root@testhost01:/home/test/Desktop# root@testhost01:/home/test/Desktop# su dx1a $ w 08:34:46 up 26 min, 1 user, load average: 0.16, 0.12, 0.11 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT test :0 :0 08:12 ?xdm? 1:38 0.01s /usr/libexec/gd $ whoami dx1a Exam1:dx1a忘记自己的passwd了怎么办? 方法一:请求root帮助,删除密码后自己重置 root@testhost01:/home/test/Desktop# passwd -d dx1a passwd: password expiry information changed. root@testhost01:/home/test/Desktop# su dx1a $ passwd New password: !QAZ2wsx Retype new password: passwd: password updated successfully $ 方法二:请求root帮助,vi /etc/passwd中对应的dx1a的行,删除口令域中的“x”标记并保存 然后切换su dx1a后执行passwd重置密码。 S2、usermod、groupadd、groupdel、groupmod命令 //锁定用户账户,使口令无效,以下两个操作等同效果 root@testhost01:~# passwd -l dx1a passwd: password expiry information changed. root@testhost01:~# usermod -L dx1a 将现有用户账户添加到组,将dx1a添加到组student中 root@testhost01:~# usermod -a -G student dx1a root@testhost01:~# id dx1a uid=1001(dx1a) gid=1001(dx1a) groups=1001(dx1a),1002(student) 创建一个新用户并使用单个命令将其分配给primary和secondary(主要和次要组)。用id命令验证。 root@testhost01:~# useradd -g users dx1b root@testhost01:~# id dx1b uid=1002(dx1b) gid=100(users) groups=100(users) 使用getent group查看linux 中多个系统组,还可以使用cat /etc/group显示 若要查看当前用户的组信息,使用groups命令: root@testhost01:~# groups dx1a dx1a : dx1a student root@testhost01:~# groups dx1b dx1b : users groupmod命令用于修改用户组的名称或GID 命令:groupmod -n newgroup oldgroup root@testhost01:~# groupmod -n stu student root@testhost01:~# 先设置stu组的密码,然后用groupmod -p修改stu组的密码为student root@testhost01:~# gpasswd stu Changing the password for group stu New Password: Re-enter new password: root@testhost01:~# groupmod -p student stu root@testhost01:~# groupdel删除用户组命令 略 |