菜鸟学Linux 第011篇笔记 Linux权限和权限管理
Command
权限管理
三类用户 user属主 group属组 others其它
chown (change file owner and group)
e.g. chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown -R user4:mygroup file1
-R --recursive 递归修改文夹里的文件属性
--reference=/path/somewhere 会参考所给文件属性改为所指定的文件属性
chgrp (change group ownership)
-R 同chown
--reference=/path/somewhere 同上chown\
chmod (change file access permissions)
修改三类用户权限
chmod 775 file (注意权限位数要给够,不然会在前边补0)
-R recursive
--reference=RFILE file
修改某类用户或某些类用户权限
u,g,o,a
chmod u=rwx file
chmod ug=rx file 同 chmod u=rx,g=rx file
修改某类用户的某位或某些位权限
u,g,o,a
chmod 用户类别+|-rwx file
chmod u-x file
chmod u+x,g-x file
chmod a+wx /tmp/abc or chmod +wx /tmp/abc
手动创建加密字符串
openssl passwd -1 -salt 'kfjekl'
Umask 遮罩码
此代码用来决定用户所创建的文件和目录的默认权限
文件默认不能具有执行权限,如果根据umask算得结果中有执行权限,
则将其权限+1
666-umask
777-umask
e.g. 输入umask则显示当前umask为多少 如为002
用户默认创建文件权限为666-002=664 即 rw-rw-r--
用户默认创建目录权限为777-002=775 即 rwxrwxr-x
站在用户登录的角度来说shell的类型
登录式shell
正常通过某终端登录
su - username
su -l username
非登录式shell
su username
图形终端下打开命令窗口
自动执行的shell脚本
登录式shell如何读取配置文件
1./etc/profile
2./etc/profile.d/*sh
3.~/.bash_profile
4.~/.bashrc
6./etc/bashrc
非登录式shell读取配置顺序
1.~/.bashrc
2./etc/bashrc
3./etc/profile.d/*sh
bash配置文件:
全局配置
/etc/profile, /etc/profile.d/*.sh, /etc/bashrc
个人配置
~/.bash_profile, ~/.bashrc
profile类文件
设定环境变量
运行命令或脚本
bashrc类的文件
设定本地变量
定义命令别名
例:1.在用户user8登录shell时提示hello user8!
因为是只给该用户设置输出,所以只需要修改个人配置文件~/.bash_profile
里边加一行echo "Hello user8!" 即可,如果全局都设置则修改全局配置文件
/etc/profile
2.为用户user8 添加命令别名ote="cd /etc"
修改个人配置文件~/.bashrc 加入一行alias ote="cd /etc" 即可
练习: 翻译下列操作含义
useradd -M user8
cp -r /etc/skel /home/user8
chown -R user8:user8 /home/user8
chmod -R go-rwx /home/user8 同 chmod -R go= /home/user8