Linux基础命令(二)
作业一:
1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”
groupadd -g 555 netasha
useradd -u 1000 -g netasha -c "master" netasha useradd -u 1000 -c "master" netasha
groupmod -g 555 netasha
2) 修改natasha用户的家目录为/Natasha
mkdir /Netasha
usermod -d /Netasha/ netasha
tail -1 /etc/passwd
3) 查看用户信息配置文件的最后一行
tail -1 /etc/passwd
tail -1 /etc/shadow
tail -1 /etc/group
tail -1 /etc/shadow
4) 为natasha用户设置密码“123”
echo "123"|passwd --stdin netasha
5) 查看用户密码配置文件的最后一行
tail -1 /etc/shadow
6) 将natasha用户账户锁定
usermod -L netasha
7) 将natasha用户账户解锁
usermod -U netasha
8) 新建组police,gid为999
groupadd -g 999 police
9) 查看组配置文件的最后一行
tail -1 /etc/group
10) 将natasha用户加入police组
usermod -G police netasha
11) 修改police组的组名为jingcha
groupmod netasha -n jingcha
12) 删除natasha用户,连家目录和邮箱一起删除
userdel -r netasha
rm -rf /home/netasha
13) 删除jingcha组
groupdel jingcha
作业二:
1) 在用户的主目录下创建目录test,进入test创建空文件file1
[root@bogon ~]# mkdir test
[root@bogon ~]# cd test/
[root@bogon test]# touch file1
2) 以长格式形式显示文件信息,注意文件的权限和所属用户和组
[root@bogon ~]# ls -ld test/
drwxr-xr-x 2 root root 19 Mar 15 16:16 test/
[root@bogon test]# ls -l file1
-rw-r--r-- 1 root root 0 Mar 15 16:16 file1
3) 为文件file1设置权限,使其他用户可以对此文件进行写操作。
chmod o+w file1
4) 查看设置结果,
[root@bogon test]# ll
total 4
-rw-r--r-- 1 root root 8 Mar 15 16:40 file1
5) 取消同组用户对文件file1的读取权限,并查看设置结果。
[root@bogon test]# chmod g-r file1
[root@bogon test]# ll
total 4
-rw----rw- 1 root root 8 Mar 15 16:40 file1
6) 用数字表示法为文件file设置权限,所有者可读、可写、可执行,所属组用户和其他用户只具有读和执行的权限。设置完成后查看设置结果。
chmod 755 file1
[root@bogon test]# ll file1
-rwxr-xr-x 1 root root 8 Mar 15 16:40 file1
7) 用数字形式更改文件file1的权限,使所有者只能读取此文件。其他任何用户都没有权限。查看设置结果。
[root@bogon test]# chmod 400 file1
[root@bogon test]# ll file1
-r-------- 1 root root 8 Mar 15 16:40 file1
8) 回到上层目录,查看test的权限
[root@bogon test]# cd ..
[root@bogon ~]# ll -d test/
drwxr-xr-x 2 root root 19 Mar 15 16:40 test/
9) 为其他用户添加对此目录的写权限
[root@bogon ~]# chmod o+w test/
[root@bogon ~]# ll -d test/
drwxr-xrwx 2 root root 19 Mar 15 16:40 test/
作业三:
以操作文件的方式,新建一个用户alex
[root@bogon ~]# mkdir /home/alex
[root@bogon ~]# cp -r /etc/skel/.[!.]* /home/alex/
[root@bogon ~]# chown -R alex:alex /home/alex/
[root@bogon ~]# chmod 700 /home/alex/
[root@bogon ~]# ll -la /home/alex/
total 12
drwxr-xr-x 2 alex alex 62 Mar 15 17:08 .
drwxr-xr-x. 10 root root 111 Mar 15 17:08 ..
-rw-r--r-- 1 alex alex 18 Mar 15 17:08 .bash_logout
-rw-r--r-- 1 alex alex 193 Mar 15 17:08 .bash_profile
-rw-r--r-- 1 alex alex 231 Mar 15 17:08 .bashrc [root@bogon ~]# touch /var/spool/mail/alex
[root@bogon ~]# chown alex:mail /var/spool/mail/alex
[root@bogon ~]# ll /var/spool/mail/alex
-rw-r--r-- 1 alex mail 0 Mar 15 17:06 /var/spool/mail/alex [root@bogon ~]# tail -1 /etc/passwd
alex:x:1006:1006::/home/alex:/bin/bash
[root@bogon ~]# tail -1 /etc/shadow
alex:!!:17240:0:99999:7:::
[root@bogon ~]# tail -1 /etc/group
alex:x:1006:
[root@bogon ~]# tail -1 /etc/gshadow
alex:!::
作业四:
1) 新建目录/test/dir,属主为tom,数组为group1,/test目录的权限为777
[root@bogon ~]# mkdir -p /test/dir
[root@bogon ~]# chown -R tom:group1 /test/dir/
[root@bogon ~]# chmod 777 /test/
2) 新建用户jack,切换到jack用户下,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的others权限)
[root@bogon ~]# useradd jack
[root@bogon ~]# su - jack
[jack@bogon ~]$ cd /test/dir/
[jack@bogon dir]$ touch 1.txt
touch: cannot touch ‘1.txt’: Permission denied [root@bogon test]# chmod o+w dir/
[jack@bogon dir]$ touch 1.txt
touch: cannot touch ‘1.txt’: Permission denied
3)将jack加入group1组,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的group权限)
[root@bogon ~]# usermod -G group1 jack
[root@bogon ~]# chmod g+w dir/
[root@bogon ~]# su - jack
Last login: Wed Mar 15 17:22:55 CST 2017 on pts/1
[jack@bogon ~]$ cd /test/dir/
[jack@bogon dir]$ touch 1.txt
[jack@bogon dir]$ echo 123 > 1.txt
[jack@bogon dir]$ more 1.txt
123
4)切换到tom用户,验证tom用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的user权限)
[root@bogon ~]# su - tom
[tom@bogon ~]$ cd /test/dir/
[tom@bogon dir]$ touch 2.txt
[tom@bogon dir]$ echo 456 > 2.txt
[tom@bogon dir]$ cat 2.txt
456
5)在dir目录内新建文件tom.txt,属主为tom,属组为group1,/test目录的权限为777
[root@bogon dir]# touch tom.txt
[root@bogon dir]# chown tom:group1 tom.txt
[root@bogon dir]# chown 777 /test/
6)新建用户rose,切换到rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的others权限来配合验证过程)
[root@bogon ~]# useradd rose
[root@bogon ~]# su - rose
[rose@bogon ~]$ cd /test/dir/
[rose@bogon dir]$ cat tom.txt
[rose@bogon dir]$ echo 789 > tom.txt
-bash: tom.txt: Permission denied [root@bogon dir]# chmod o+w tom.txt
[rose@bogon dir]$ echo "df -h" > tom.txt
[rose@bogon dir]$ ./tom.txt
-bash: ./tom.txt: Permission denied [root@bogon dir]# chmod o+x tom.txt
[rose@bogon dir]$ ./tom.txt
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 1.8G 16G 11% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.6M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
7)将rose加入group1组,在rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的group1权限来配合验证过程)
[root@bogon ~]# usermod -G group1 rose
[root@bogon ~]# su - rose
[rose@bogon ~]$ cd /test/dir/
[rose@bogon dir]$ cat tom.txt
df -h
[rose@bogon dir]$ echo "uptime" >> tom.txt
-bash: tom.txt: Permission denied [root@bogon dir]# chmod g+w tom.txt
[rose@bogon dir]$ echo "uptime" >> tom.txt [root@bogon dir]# chmod g+x tom.txt
[rose@bogon dir]$ ./tom.txt
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 1.8G 16G 11% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
18:15:24 up 3:53, 4 users, load average: 0.00, 0.01, 0.05
8)切换到tom用户,验证tom用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的user权限来配合验证过程)
[root@bogon ~]# su - tom
[tom@bogon ~]$ cd /test/dir/
[tom@bogon dir]$ cat tom.txt
df -h
uptime
[tom@bogon dir]$ echo "free -m" >> tom.txt
[tom@bogon dir]$ ./tom.txt
-bash: ./tom.txt: Permission denied [root@bogon dir]# chmod u+x tom.txt
[tom@bogon dir]$ ./tom.txt
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 1.8G 16G 11% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
18:17:08 up 3:55, 4 users, load average: 0.00, 0.01, 0.05
total used free shared buff/cache available
Mem: 976 129 702 6 145 690
Swap: 2047 0 2047
参考链接:http://www.cnblogs.com/linhaifeng/articles/6045600.html
补充:
文件权限
- read: 能看内容
- write: 修改内容
- x: 执行文件
目录权限
- read: 浏览目录下的子目录名,子文件名
- write: 创建,重命名,删除子目录名,子文件名
- x:可以cd切换进入
Linux基础命令(二)的更多相关文章
- linux基础命令<二>
1.关机 init 0 poweroff halt shutdown –h now 2.重启 init 6 reboot shutdown –r now 3.查询都有那些用户在系统 ...
- linux基础命令学习笔记(二)
linux基础命令学习笔记(二) 1.kill :终止进程 kill pid (唯一标示一个进程) kill -9 强制终止 kill -15 命令未结束不能终止 # ps aux 查看所有进程 ...
- Linux基础练习题(二)
Linux基础练习题(二) 1.复制/etc/skel目录为/home/tuer1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限. [root@www ~]# cp -r ...
- 运维之Linux基础(二)
运维之Linux基础(二) 1. file 命令基期用法 2. 文件系统 Linux的文件系统结构是树状结构,所有的文件都在/root跟目录下 /boot:系统启动相关的文件, 如:内核.initrd ...
- Linux基础命令-查看基本硬件信息
Linux基础命令-查看基本硬件信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看CPU信息 [root@node101.yinzhengjie.org.cn ~]# l ...
- 运维 04 Shell基础命令(二)
Shell基础命令(二) 查看Linux的发行版 cat /etc/redhat-release cat /etc/os-release 查看系统用户的id信息 id 用户名 id root id ...
- Linux 基础命令及基本目录
Linux 基础命令及基本目录 一.网卡 1.网卡配置文件路径 /etc/sysconfig/network-scripts/ifcfg-eth0 配置文件: TYPE=Ethernet # 以太 ...
- Linux——基础命令用法(上)
一.Linux基础命令 1.Linux命令行的格式 命令行的格式为:用户名+主机名+当前工作目录 输入内容的命令格式为:命令 [-短选项/--长选项] [参数] [root@localhost ~]# ...
- 第四节,Linux基础命令
第四节,Linux基础命令 命令是系统操作员对系统传入的指令,传入指令后回车,系统接收到指令做出相应的行为 1.查看用户位于系统什么位置 [pmd]检查操作用户位于系统的什么位置 命令 ...
随机推荐
- Application Architecture Determines Application Performance
 Application Architecture Determines Application Performance Randy Stafford AppliCATion ARCHiTECTuR ...
- Resources.FindObjectsOfTypeAll<T>()的坑(Ghost prefab)
今天遇到了一个Bug,因为调用Resources.FindObjectsOfTypeAll<T>()遍历整个场景,结果遍历出的对象不对.比较哈希一查果然是两个.原来prefab本身和pre ...
- iOS开发多线程篇 03 —线程安全
iOS开发多线程篇—线程安全 一.多线程的安全隐患 资源共享 1块资源可能会被多个线程共享,也就是多个线程可能会访问同一块资源 比如多个线程访问同一个对象.同一个变量.同一个文件 当多个线程访问同一块 ...
- hive2.1.1配置
hive2.1.1配置 首先在conf下复制hive-site.xml <property> <name>javax.jdo.option.ConnectionURL</ ...
- angularjs 手动启动
谷歌推的javascript框架angulajs相当火热,由于新项目的缘故,最近一直看angularjs.在看的时候,一直有个疑问,angularjs 核心依赖于DI(依赖注入).常用的方法是在页面的 ...
- 页面中添加qq客服
html页面 <html> <head> <meta http-equiv="Content-Type" content="text/htm ...
- java部署ubuntu后中文显示问号问题
1.首先先回忆自身项目的编码格式,即在本地进行编码时使用的编码格式.UTF-82.检测tomcat的设置问题,在web.xml和server中的设置:server.xml中: <Connecto ...
- 解决使用VS2013创建的MVC项目在VS2015中打开的各种问题
其实很多问题一直都存在,但是因为其不影响编译结果和运行结果,所以我也就一直没理它.但是问题放在那一直存在,偶尔想起来还有某些问题没解决的时候心里总是感觉不得劲,所以今天就彻底的查查资料解决了. 问题一 ...
- 【BZOJ】3203: [Sdoi2013]保护出题人(几何+三分+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=3203 wa无数次QAQ,犯sb错....一是数组没有引用...二是输出转成了int(越界了sad). ...
- Codeforces Round #268 (Div. 2) (被屠记)
c被fst了................ 然后掉到600+.... 然后...估计得绿名了.. sad A.I Wanna Be the Guy 题意:让你判断1-n个数哪个数没有出现.. sb题 ...