From c090814749b74f46f0458b9fea6ae6e73efdcabe Mon Sep 17 00:00:00 2001 From: z <11@qq.com> Date: Wed, 12 Jun 2024 16:37:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\256\214Debian\346\255\245\351\252\244.md" | 81 +++++++++++++++++++ ...21\345\222\214\347\256\241\351\201\223.md" | 66 +++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 "02\350\265\265\345\206\254\350\216\271/2024-06-11\345\210\232\345\256\211\350\243\205\345\256\214Debian\346\255\245\351\252\244.md" create mode 100644 "02\350\265\265\345\206\254\350\216\271/2024-06-12\351\207\215\345\256\232\345\220\221\345\222\214\347\256\241\351\201\223.md" diff --git "a/02\350\265\265\345\206\254\350\216\271/2024-06-11\345\210\232\345\256\211\350\243\205\345\256\214Debian\346\255\245\351\252\244.md" "b/02\350\265\265\345\206\254\350\216\271/2024-06-11\345\210\232\345\256\211\350\243\205\345\256\214Debian\346\255\245\351\252\244.md" new file mode 100644 index 0000000..cd1bf83 --- /dev/null +++ "b/02\350\265\265\345\206\254\350\216\271/2024-06-11\345\210\232\345\256\211\350\243\205\345\256\214Debian\346\255\245\351\252\244.md" @@ -0,0 +1,81 @@ +```bash +1.设置国内软件源镜像:/etc//apt/sources.list +2.更新软件包列表:apt update +3.更新系统:apt upgrade -y +4.安装vim:apt install vim -y +5.编辑网卡配置,设置静态IP: +vim /etc/network/interfaces + +重新启动网络服务: +sudo systemctl restart networking +常用命令; + +1.time(用于测量命令的执行时间) +- real:总的时间(墙上时钟时间)。 +- user:用户态 CPU 时间。 +- sys:内核态 CPU 时间。 + +2.date(显示或设置系统日期和时间) +- %Y:四位数的年份。 +- %m:两位数的月份。 +- %:两位数的日期。 + +3.timedatectl(查看和设置系统时间和日期,时区和 NTP(网络时间协议)设置) +- NTP:网络时间协议,用于同步时间。 +- RTC:实时时钟。 + +4.reboot(重新启动系统) +- systemd:系统和服务管理器。 + +5.poweroff(关闭系统电源) +- halt:停止系统所有的 CPU 功能。 + +6.wget(从网络上下载文件) +- URL:统一资源定位符。 +- HTTP/HTTPS:超文本传输协议。 + +7.curl(从网络上获取或发送数据) +- URL:统一资源定位符。 +- GET/POST:HTTP 请求方法。 + +8.ps(查看当前运行的进程) +- PID:进程标识符。 +- TTY:终端类型。 + +9.kill(向进程发送信号(通常用于终止进程)) +- SIGTERM:请求中止进程。 +- SIGKILL:强制终止进程。 + +10.ip(显示和操作网络接口和路由) +- address:IP 地址。 +- route:路由信息。 + +11.ss(显示套接字统计信息。旧版是netstat) +- TCP:传输控制协议。 +- UDP:用户数据报协议。 + +12.uname(显示系统信息) +- kernel:操作系统内核。 +- OS:操作系统。 + +13.uptime(显示系统运行时间和负载) +- load average:系统平均负载 + +14.who(显示当前登录用户信息) +- login:用户登录信息。 +- TTY:终端类型。 + +15.last(显示系统上最近的登录信息) +- wtmp:记录登录和注销事件的文件。 + +16.ping(测试网络连通性) +- ICMP:互联网控制消息协议。 +- echo request:回显请求。 + +17.traceroute(显示到达网络主机的路径) +- hop:从一个网络节点到另一个的跳转。 +- TTL:生存时间。 + +18.history(显示命令历史记录) +- bash history:记录用户输入的命令历史。 +``` \ No newline at end of file diff --git "a/02\350\265\265\345\206\254\350\216\271/2024-06-12\351\207\215\345\256\232\345\220\221\345\222\214\347\256\241\351\201\223.md" "b/02\350\265\265\345\206\254\350\216\271/2024-06-12\351\207\215\345\256\232\345\220\221\345\222\214\347\256\241\351\201\223.md" new file mode 100644 index 0000000..f5aca27 --- /dev/null +++ "b/02\350\265\265\345\206\254\350\216\271/2024-06-12\351\207\215\345\256\232\345\220\221\345\222\214\347\256\241\351\201\223.md" @@ -0,0 +1,66 @@ +## 重定向和管道 + +```bash +常用的文件描述符包括: + 0:标准输入:键盘输入 + 1:标准输出:直接显示在屏幕,不包含错误信息 + 2:标准错误:只包含错误信息 + +输出重定向 + 1.覆盖输出重定向 > + 将命令的标准输出重定向到一个文件,如果文件已经存在,则覆盖它 + ls > 1.txt + 这个命令将ls命令的输出保存到1.txt文件中,如果文件已存在,则会被覆盖 + + 2.追加输出重定向 >> + 将命令的标准输出追加到一个文件的末尾,如果文件不存在,则创建它 + echo "Hello" >> 2.txt + 这个命令会将"Hello"追加到2.txt文件中 + + 3.注意: + 标准输出不含错误信息 + +输入重定向 + 1.输入重定向 < + 将文件的内容作为命令的输入 + #原本的内容 + orange + banana + apple + 命令: sort < 3.txt + #使用命令后的内容 + apple + banana + orange + 将3.txt文件的内容作为‘sort’命令的输入进行排序 + + +错误重定向 + 1.错误输出重定向 2> + 将命令的错误输出重定向到一个文件 + reboot 2> 4.txt + 这个命令会将错误的信息保存到4.txt文件中 + + 2.错误输出追加重定向 2>> + 将命令的错误输出追加到一个文件 + reboot 2>> 3.txt + 这个命令会将reboot的错误信息追加到3.txt文件中 + + 3.同时重定向标准输出和标准错误输出 + 使用 &> 符号将标准输出和错误输出同时重定向到同一个文件 + command &> 5.txt #正确和错误原版混搭,原封不动 + command > 1.txt 2>&1 #正确和错误原版混搭,原封不动 + command > 1.txt 2>> 1.txt #先正确后错误 + command 2> 1.txt >> 1.txt #先错误后正确 + + +管道符 | + 1.将命令的输出传递给另一个命令 + ls -l | grep "txt" + 这个命令会将ls -l 的输出传递给grep 'txt',只显示包含“txt”的行 + + 2.多命令链式操作 + ps aux | grep "sshd" | awk '{print $2}' + 这个命令链会列出所以进程(ps aux),然后过滤包含"sshd"的行(grep 'sshd'),最后提取进程ID(awk '{print $2}') +``` + -- Gitee From f783b1c68ed62e2f82ec1ce4e6b7048c58050d59 Mon Sep 17 00:00:00 2001 From: zhao <3476471081@qq.com> Date: Fri, 14 Jun 2024 19:18:29 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AE=A1=E7=90=86=E7=BB=83=E4=B9=A0=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...06\347\273\203\344\271\240\351\242\230.md" | 267 ++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 "02\350\265\265\345\206\254\350\216\271/2024-06-14\347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204\347\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" diff --git "a/02\350\265\265\345\206\254\350\216\271/2024-06-14\347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204\347\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" "b/02\350\265\265\345\206\254\350\216\271/2024-06-14\347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204\347\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000..63f1a67 --- /dev/null +++ "b/02\350\265\265\345\206\254\350\216\271/2024-06-14\347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204\347\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,267 @@ +1. 创建/guanli 目录,在/guanli下创建zonghe 和 jishu 两个目录(一条命令) + + ```bash + root@hecs-235925:~# mkdir -p /guanli/zonghe &&mkdir /guanli/jishu + ``` + +2. 添加组帐号zonghe、caiwu、jishu,GID号分别设置为2001、2002、2003 + + ```bash + root@hecs-235925:~# groupadd -g 2001 zonghe + root@hecs-235925:~# groupadd -g 2002 caiwu + root@hecs-235925:~# groupadd -g 2003 jishu + ``` + +3. 创建jerry、kylin、tsengia、obama用户,其中的kylin用户帐号在2020年12月30日后失效 + + ```bash + root@hecs-235925:~# useradd jerry && useradd -e 2020-12-30 kylin && useradd tsengia && useradd obama + ``` + + + +4. 将jerry、kylin、tsengia、obama等用户添加到zonghe组内 + + ```bash + root@hecs-235925:~# gpasswd -M jerry,kylin,tsengia,obama zonghe + ``` + + + +5. 创建handy、cucci用户,其中cucci帐号的登录Shell设置为“/sbin/nologin” + + ```bash + root@hecs-235925:~# useradd handy && useradd cucci + root@hecs-235925:~# usermod -s /sbin/nologin cucci + ``` + + + +6. 将handy、cucci等用户添加到jishu组内 + + ```bash + root@hecs-235925:~# gpasswd -M handy,cucci jishu + ``` + + + +7. 将上述的所有用户均要求加入到guanli组内 + + ```bash + root@hecs-235925:~# groupadd guanli + root@hecs-235925:~# gpasswd -M jerry,kylin,tsengia,obama,handy,cucci guanli + ``` + + + +8. 将zonghe组内的obama用户删除 + + ```bash + root@hecs-235925:~# gpasswd -d obama zonghe + Removing user obama from group zonghe + ``` + + + +9. 为jerry用户设置密码为“123456”(使用普通方法)为cucci用户设置密码为“redhat” + + ```bash + root@hecs-235925:~# passwd jerry + root@hecs-235925:~# echo "redhat" | passwd --stdin cucci + ``` + + + +10. 将jerry用户锁定,并查看锁定状态 + + ```bash + root@hecs-235925:~# usermod -L jerry + root@hecs-235925:~# passwd -S jerry + jerry L 06/14/2024 0 99999 7 -1 + ``` + + + +11. 打开两个xshell窗口,通过(who 或者 w)命令查看连接状态,并通过fuser杀掉其中一个 + + ```bash + zdy18@hecs-235925:~$ sudo apt-get update + zdy18@hecs-235925:~$ sudo apt-get install psmisc + zdy18@hecs-235925:~$ who + zdy18@hecs-235925:~$ fuser -k/dev/pts/1 + ``` + + + +12. 查看cucci用户,属于那些组,并查看其详细信息 + + ```bash + root@hecs-235925:~# groups cucci + zdy18@hecs-235925:~$ sudo apt-get install finger + zdy18@hecs-235925:~$ finger cucci + + ``` + + + +13. 手工创建账号student(预留) + + ```bash + root@hecs-235925:~# vi /etc/passwd + student:x:1014:1014::/home/student:/bin/bash + root@hecs-235925:~# vi /etc/shadow + student::18107:0:99999:7::: + root@hecs-235925:~# vi /etc/group + student:x:1014: + root@hecs-235925:~# mkdir /home/student + root@hecs-235925:~# cd /etc/skel/ + root@hecs-235925:~skel# ls -a | cp .b* /home/student/ + ``` + + + +14. 设置权限及归属:/guanli目录属组设为guanli, /guanli/zonghe目录的属组设为zonghe /guanli/jishu目录的属组设为jishu,设置3个目录都是禁止其他用户访问的权限 + + ```bash + root@hecs-235925:~# chown :guanli /guanli + root@hecs-235925:~# chown :zonghe /guanli/zonghe + root@hecs-235925:~# chown :jishu /guanli/jishu + root@hecs-235925:~# chmod -R o-rwx /guanli/ + ``` + + + +15. 建立公共目录/ceshi允许技术组内的所有用户读取、写入、执行文件, 禁止其他用户读、写、执行 + + ```bash + root@hecs-235925:~# mkdir /ceshi + root@hecs-235925:~# chown .jishu /ceshi/ + root@hecs-235925:~# chmod 770 /ceshi/ + root@hecs-235925:~# ls -ld /ceshi + drwxrwx--- 2 root jishu 4096 Jun 14 19:12 /ceshi + ``` + + + +16. 清除jerry用户密码 + + ```bash + root@hecs-235925:~# passwd -d jerry + passwd: password expiry information changed. + ``` + + + +17. 锁定cucci用户密码并查看状态 + + ```bash + root@hecs-235925:~# passwd -l cucci + passwd: password expiry information changed. + root@hecs-235925:~# passwd -S cucci + cucci L 06/14/2024 0 99999 7 -1 + ``` + + + +18. 修改obama用户的UID为8888 + + ```bash + root@hecs-235925:~# id obama + uid=1021(obama) gid=1021(obama) groups=1021(obama),2004(guanli) + root@hecs-235925:~# usermod -u 8888 obama + root@hecs-235925:~# id obama + uid=8888(obama) gid=1021(obama) groups=1021(obama),2004(guanli) + ``` + + + +19. 通过passwd命令修改kylin用户的最长密码使用期限为60天 + + ```bash + root@hecs-235925:~# passwd -x 60 kylin + passwd: password expiry information changed. + root@hecs-235925:~# cat /etc/shadow |grep "kylin" + kylin:!:19888:0:60:7::18626: + ``` + + + +20. 通过id groups等命令查看用户handy信息 + + ```bash + root@hecs-235925:~# id handy + uid=1022(handy) gid=1022(handy) groups=1022(handy),2003(jishu),2004(guanli) +root@hecs-235925:~# groups handy + handy : handy jishu guanli + ``` + + + +- 用户管理 + - 添加账户 useradd -m -s /bin/bash db2 + - 删除账户 userdel -r db2 + - 修改账户 usermod [选项同添加账户] db2 + - 查看帐户 getent passwd db2 +- 用户组管理 + - 添加用户组 groupadd stu1 + - 删除用户组 groupdel stu1 + - 添加用户到用户组 usermod -aG stu1 db2 +- 密码管理 + - 设置密码 passwd +- sudo权限管理 + - usermod -aG sudo xxx + - 修改/etc/sudoers文件 +- 登录权限管理 +- 用户环境管理 + - 用户配置文件 : .bashrc + - 用户环境变量: $PATH、$HOME、$SHELL + +## 文件与目录的权限管理 + +- https://www.runoob.com/linux/linux-file-attr-permission.html + + ![20240605092950](./assets/20240605092950.png) + +- 文件类型 + + - -普通文件 + - d目录 + - l连接文件 + - b c s p 等其它文件 + +- 基本权限 + + - r 读 + - w 写 + - x 执行 + +- 权限表示 + + - 字符表示 + - 数字表示 + - 4 代表 r + - 2 代表 w + - 1 代表 x + - 权限修改 + - chmod 修改权限 + - chown 修改拥有者 + - chgrp 修改所属组 + - 权限的继承 + - 目录权限下文件和目录的影响 + - umask + - 特权权限 + - SUID + - SGID + - SBIT + - 隐藏权限 + - i + - 用在文件上,无法对该文件进行任何修改 + - 用在目录上,无法在里面创建新文件,但可以修改已有文件 + - a + - 除了可追加内容外,无法进行其它修改 + - 隐藏权限的操作 + - 修改隐藏权限 chattr + - chattr +i XXX + - chattr -i XXX + - 查看隐藏权限 + - lsattr \ No newline at end of file -- Gitee From 3c5a076f12fa8844dd7beaa8ace0cedaf4c9403f Mon Sep 17 00:00:00 2001 From: zhao <3476471081@qq.com> Date: Fri, 14 Jun 2024 19:36:44 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=BB=83=E4=B9=A0=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/02\350\265\265\345\206\254\350\216\271/2024-06-14\347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204\347\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" "b/02\350\265\265\345\206\254\350\216\271/2024-06-14\347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204\347\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" index 63f1a67..d063a9f 100644 --- "a/02\350\265\265\345\206\254\350\216\271/2024-06-14\347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204\347\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" +++ "b/02\350\265\265\345\206\254\350\216\271/2024-06-14\347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204\347\256\241\347\220\206\347\273\203\344\271\240\351\242\230.md" @@ -67,7 +67,7 @@ ```bash root@hecs-235925:~# passwd jerry - root@hecs-235925:~# echo "redhat" | passwd --stdin cucci + root@hecs-235925:~# passwd redhat ``` -- Gitee