命令行与shell编程系列之文件权限

命令行与shell编程系列文章目录

第一章 什么是命令行
第二章 文件权限
第三章 文件的处理
第四章 磁盘和文件系统
第五章 理解shell解析器和shell进程



前言

在linux系统中,系统必须要提供一套保护文件安全性的机制。在linux中用户账户是进入系统的第一道关卡,需要知道用户ID和用户密码。其中涉及到用户的创建和删除以及linux用户组的概念。具体介绍可查看《Linux命令行和shell脚本编程大全》等书籍

1. 用户的创建和删除

zhang:~$ sudo adduser  test1
sudo: unable to resolve host zhangguoting
Adding user `test1' ...
Adding new group `test1' (1001) ...
Adding new user `test1' (1001) with group `test1' ...
Enter new UNIX password: 
Retype new UNIX password: 
Sorry, passwords do not match
passwd: Authentication token manipulation error
passwd: password unchanged
Try again? [y/N] y
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for test1
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] 

zhang:~$ tail /etc/passwd
Daemon,,,:/:/bin/false
pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false
rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false
saned:x:119:127::/var/lib/saned:/bin/false
usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false
zhang:x:1000:1000:zhang,,,:/home/zhang:/bin/bash
mysql:x:121:129:MySQL Server,,,:/nonexistent:/bin/false
statd:x:122:65534::/var/lib/nfs:/bin/false
telnetd:x:123:130::/nonexistent:/bin/false
sshd:x:124:65534::/var/run/sshd:/usr/sbin/nologin
test1:x:1001:1001:,,,:/home/test1:/bin/bash

zhang:~$ sudo deluser  --remove-home  test1
sudo: unable to resolve host zhangguoting
Looking for files to backup/remove ...
Removing files ...
Removing user `test1' ...
Warning: group `test1' has no more members.
Done.

2. 组的创建删除以及添加用户

zhang:~$ tail /etc/group
pulse:x:124:
pulse-access:x:125:
rtkit:x:126:
saned:x:127:
zhang:x:1000:
sambashare:x:128:zhang
mysql:x:129:
telnetd:x:130:
test1:x:1001:
shared:x:1002:

zhang:~$ sudo delgroup  shared
sudo: unable to resolve host zhangguoting
Removing group `shared' ...
Done.

zhang:~$ sudo usermod  -G shared  test1 
zhang:~$ tail /etc/group
pulse:x:124:
pulse-access:x:125:
rtkit:x:126:
saned:x:127:
zhang:x:1000:
sambashare:x:128:zhang
mysql:x:129:
telnetd:x:130:
test1:x:1001:
shared:x:1002:test1

3. 修改文件权限和所属关系

zhang:~$ ls -alh file1 
-rw-rw-r-- 1 zhang zhang 0 4月  13 15:52 file1

上面的d表示这是目录
接下来3位字母一组共3组 分别是属主、属组和其他的文件权限
r - 可读
w - 可写
x = 可执行

zhang:~$ chmod  764 file1 
zhang:~$ ls -alh file1 
-rwxrw-r-- 1 zhang zhang 0 4月  13 15:52 file1

其中的764每一位数字是8进制的数字,分别对应rwx3位标志

上述测试在Ubuntu系统内,部分其他系统的命令行会有所差异,比如命令adduser 在其他系统对应的是useradd,其他命令也是一样的情况(实际上adduser和useradd是有较大区别)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值