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]检查操作用户位于系统的什么位置 命令 ...
随机推荐
- unity Editor下自启动
[InitializeOnLoad] 加上这个特性,并且在静态构造函数里写上内容.即可在Unity启动的时候自启动这个Editor脚本
- HTTP 用户认证
HTTP 常见的用户认证可以分为下面三种: 基于IP,子网的访问控制(ACL) 基本用户验证(Basic Authentication) 消息摘要式身份验证(Digest Authentication ...
- java中for循环执行过程
for (int j = 0; j < newSize; j++) { //执行todo } 1.首先变量j初始化为0 2.然后j=0的值跟newSize进行比较,假如为true,则执行{}里面 ...
- iOS 解决xcode设置全局断点后 执行视频播放时自动进入断点cxa_throw
iOS中遇到报错,然后断点停留在了libc++abi.dylib`__cxa_throw:里面,这是因为C++文件异常,一般直接点击下一个断点就能跳过去,然后项目还是继续可以运行. 解决方案 右键编辑 ...
- jQuery 时间戳转化成时间
//时间转换 function formatDate(now) { var now= new Date(now); var year=now.getFullYear(); ...
- php中while($row = $results->fetch_row())调用出错
php中while($row = $results->fetch_row())调用出错 错误处在sql语句上
- 基于WebBrowser 的爬虫程序
WebBrowser的属性和事件 WebBrowser 如何跳转页面 web.Navigate(""); WebBrowser 如何循环跳转获取页面内容 bool loading ...
- JavaWeb——过滤器
过滤器简介 WEB过滤器是一个服务器端的组件,它可以截取用户端的请求与相应信息,并对这些信息过滤. 过滤器的工作原理和生命周期 在没有Web过滤器的情况下,用户直接访问服务器上的Web资源.但是如果存 ...
- ==和Equal()的区别
我们在编程的时候,经常会遇到判断两个对象是否相等的情况.说到判断两个对象是否相等,就不得不说对象的类型和对象在内存中的存储情况. 对象类型可以分为值类型和引用类型: 值类型包括:简单类型.结构类型.枚 ...
- java垃圾回收算法和垃圾收集器
垃圾收集算法.垃圾回收算法.java垃圾收集器 目录1. 垃圾收集算法1)引用计数法2)根搜索法2. 垃圾回收算法1)复制算法2)标记-清除算法3)标记-整理算法4)分代收集算法3. java垃圾收集 ...