linux基础-权限管理,手工添加用户,umask,bash配置文件
权限管理:
r:
w:
x:
三类用户:
u: 属主
g: 属组
o: 其它用户
chown: 改变文件属主,不会修改内部子文件(只有管理员可以使用此命令)
# chown USERNAME file,...
-R: 修改目录及其内部文件的属主
--reference=/path/to/somefile file,... (修改文件属主与某文件保持一直)
chown --refernce=/tmp/abc /tmp/test
ll /tmp/test
ll /tmp/abc
# chgrp GRPNAME file,... 改变文件属组(只有管理员可以使用此命令)
-R
--reference=/path/to/somefile file,...
可以同时修改属主和属组
chown USERNAME:GRPNAME file,...
chown USERNAME.GRPNAME file,...
chmod: 修改文件的权限
修改三类用户的权限:
chmod MODE file,...
chmod 750 /etc/test (
ll /etc/test
-R:修改目录及其内部文件的属主
--reference=/path/to/somefile file,... (修改文件属主与某文件保持一直)
rwxr-x---
修改某类用户或某些类用户权限:
u,g,o,a
chmod u=rwx /tmp/abc
ll /tmp/abc
chmod g=r,u=r /tmp/abc
chmod go=r /tmp/abc
chmod 用户类别=MODE file,...
修改某类用户的某位或某些位权限:
u,g,o,a
chmod 用户类别+|-MODE file,...
chmod u-x /tmp/abc
ll /tmp/abc
chmod a+x /tmp/abc
chmod +x /tmp/abc
练习:
1、新建一个没有家目录的用户openstack;
# useradd -M openstack
2、复制/etc/skel为/home/openstack;
# cp -r /etc/skel /home/openstack
# ll /home/openstack
3、改变/home/openstack及其内部文件的属主属组均为openstack;
# chown -R openstack:openstack /home/openstack
4、/home/openstack及其内部的文件,属组和其它用户没有任何访问权限
# chmod -R go= /home/openstack
手动添加用户,模拟useradd功能(练习)
手动添加用户hive, 基本组为hive (5000),附加组为mygroup
ll `which passwd`
nano /etc/group
mygroup:x:501:hive
hive:x:5000:
nano /etc/passwd
hive:x:5000:5000:Hive:/home/hive:/bin/bash
nano /etc/shadow
hive:!!:17125:0:99999:7:::
修改家目录用户/组/权限
root@localhost ~]# cp -r /etc/skel/ /home/hive
[root@localhost ~]# ll
total 64
-rw-------. 1 root root 4080 Jun 21 2015 anaconda-ks.cfg
-rw-r--r--. 1 root root 42001 Jun 21 2015 install.log
-rw-r--r--. 1 root root 9154 Jun 21 2015 install.log.syslog
[root@localhost ~]# ll /home/hive/
total 0
[root@localhost ~]# ll /home/hive/ -a
total 28
drwxr-xr-x. 4 root root 4096 Nov 19 19:59 .
drwxr-xr-x. 4 root root 4096 Nov 19 19:59 ..
-rw-r--r--. 1 root root 18 Nov 19 19:59 .bash_logout
-rw-r--r--. 1 root root 176 Nov 19 19:59 .bash_profile
-rw-r--r--. 1 root root 124 Nov 19 19:59 .bashrc
drwxr-xr-x. 2 root root 4096 Nov 19 19:59 .gnome2
drwxr-xr-x. 4 root root 4096 Nov 19 19:59 .mozilla
[root@localhost ~]# chown -R hive.hive /home/hive/
[root@localhost ~]# ll /home/hive/ -a
total 28
drwxr-xr-x. 4 hive hive 4096 Nov 19 19:59 .
drwxr-xr-x. 4 root root 4096 Nov 19 19:59 ..
-rw-r--r--. 1 hive hive 18 Nov 19 19:59 .bash_logout
-rw-r--r--. 1 hive hive 176 Nov 19 19:59 .bash_profile
-rw-r--r--. 1 hive hive 124 Nov 19 19:59 .bashrc
drwxr-xr-x. 2 hive hive 4096 Nov 19 19:59 .gnome2
drwxr-xr-x. 4 hive hive 4096 Nov 19 19:59 .mozilla
[root@localhost ~]# chmod -R go= /home/hive/
[root@localhost ~]# ll /home/hive/ -ad
drwx------. 4 hive hive 4096 Nov 19 19:59 /home/hive/
[root@localhost ~]# ll /home/hive/ -a
total 28
drwx------. 4 hive hive 4096 Nov 19 19:59 .
drwxr-xr-x. 4 root root 4096 Nov 19 19:59 ..
-rw-------. 1 hive hive 18 Nov 19 19:59 .bash_logout
-rw-------. 1 hive hive 176 Nov 19 19:59 .bash_profile
-rw-------. 1 hive hive 124 Nov 19 19:59 .bashrc
drwx------. 2 hive hive 4096 Nov 19 19:59 .gnome2
drwx------. 4 hive hive 4096 Nov 19 19:59 .mozilla
[root@localhost ~]#
手动生成加密密码
[root@localhost ~]# openssl passwd -1 -salt '12345678'
Password:
$1$12345678$0ME5N6oDyoEAwUp7b5UDM/
nano /etc/shadow
hive:$1$12345678$0ME5N6oDyoEAwUp7b5UDM/:17125:0:99999:7:::
校验hive是否正常
[root@localhost ~]# su - hive
[hive@localhost ~]$ ll
total 0
[hive@localhost ~]$ touch test
[hive@localhost ~]$ ll
total 0
-rw-rw-r--. 1 hive hive 0 Nov 19 20:04 test
[hive@localhost ~]$ mkdir testdir
[hive@localhost ~]$ ll
total 4
-rw-rw-r--. 1 hive hive 0 Nov 19 20:04 test
drwxrwxr-x. 2 hive hive 4096 Nov 19 20:04 testdir
[hive@localhost ~]$
遮罩码:umask
(rw-rw-rw-)666-umask:创建文件(默认没有执行权限,如果有x权限,自动加+1)
(rwxrwxrwx)777-umask:创建目录
普通用户umask:002(-------w-)
[rhel@localhost ~]$ umask
0002
[rhel@localhost ~]$
[rhel@localhost tmp]$ touch test2.txt
[rhel@localhost tmp]$ ll test2.txt
-rw-rw-r--. 1 rhel rhel 0 Nov 19 18:32 test2.txt
管理员umask:022(----w--w-)
[root@localhost tmp]# umask
0022
[root@localhost tmp]#
[root@localhost tmp]# touch test.txt
[root@localhost tmp]# ll test.txt
-rw-r--r--. 1 root root 0 Nov 19 18:31 test.txt
计算器
bc
[root@localhost tmp]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1*2
2
exit
0
q
0
^C
(interrupt) Exiting bc.
登录式shell:
正常通常某终端登录
su - USERNAME
su -l USERNAME
非登录式shell:
su USERNAME
图形终端下打开命令窗口
自动执行的shell脚本
bash的配置文件:
全局配置(/etc/)
/etc/profile, /etc/profile.d/*.sh, /etc/bashrc
个人配置(~/)
~/.bash_profile, ~/.bashrc
profile类的文件:
设定环境变量
运行命令或脚本
bashrc类的文件
设定本地变量
定义命令别名
登录式shell如何读取配置文件?
/etc/profile --> /etc/profile.d/*.sh --> ~/.bash_profile --> ~/.bashrc (个人设置)--> /etc/bashrc(全局配置)
非登录式shell如何配置文件?(不读取环境设置,/etc/profile,~/.bash_profile)
~/.bashrc --> /etc/basrc --> /etc/profile.d/*.sh
nano .bashrc
alias cls="clear"
su - root
cls
nano ~/.bash_profile
echo "hello world, welcome to cxiong's world, it's `date`"
[rhel@localhost ~]$ su - root
Password:
hello world, welcome to cxiong's world, it's Sat Nov 19 19:01:59 PST 2016
[root@localhost ~]#
转载于:https://blog.51cto.com/f1yinsky/1898258
linux基础-权限管理,手工添加用户,umask,bash配置文件相关推荐
- linux权限命令chgrp,Linux 基础——权限管理命令chown、chgrp
一.chown命令与chgrp命令的作用 有时你需要改变文件或目录的属主,比如有人离职或开发人员创建了一个在测试或生产环境中需要归属在系统账户下的应用.Linux提供了两个命令来实现这个功能:chow ...
- Linux 基础——权限管理命令chmod
一.Linux中的文件权限与目录权限 Linux中定义了3种访问权限,分别是r.w.x.其中r表示对象是可读的,w表示对象是可写的,x表示对象是可执行的,这3种权限组成一组rwx分别对应对象的3个安全 ...
- Linux基础命令行-----useradd添加用户
-c comment:描述新用户账号,通常为用户全名. -d home_dir:设置用户主目录,默认值 I为用户的登录名,并放在"/home"目录下. -D:创建新账号后保存为新账 ...
- Linux 基础——权限管理命令chown、chgrp
一.chown命令与chgrp命令的作用 有时你需要改变文件或目录的属主,比如有人离职或开发人员创建了一个在测试或生产环境中需要归属在系统账户下的应用.Linux提供了两个命令来实现这个功能:chow ...
- linux基础篇-10,权限管理chown chgrp chmod umask
linux用户及权限详解 权限管理 chown chgrp chmod umask ################################################ chown:修改属 ...
- linux组权限管理,Linux组管理和权限管理
⒈Linux组基本介绍 1)在Linux中的每个用户必须属于一个组,不能独立于组外. 2)Linux中每个文件都有所有者.所在组.其它组的概念 ①所有者 一般(默认)为文件的创建者,谁创建了该文件,就 ...
- 运维基本功(七): Linux的权限管理操作
本文是在课程课件基础上修改的学习笔记 课程原地址:https://www.bilibili.com/video/BV1nW411L7xm 如有侵删 运维基本功(一):Linux系统安装 运维基本功(二 ...
- linux更改权限报io错误,用户命令、权限、IO重定向、grep
/etc/passwd: 用户名:密码:UID:GID:注释:家目录:默认SHELL /etc/group: 组名:密码:GID:以此组为其附加组的用户列表 /etc/shadow: 用户名:密码:最 ...
- linux之权限管理命令
第一章 linux之帮助命令 第二章 linux命令行快捷键 第三章 linux之防火墙 第四章 linux之服务开机自启 第五章 linux之关机与重启 第六章 linux之环境变量 第七章 lin ...
最新文章
- 对象拷贝类PropertyUtils,BeanUtils,BeanCopier的技术沉淀
- 使用 css/less 动态更换主题色(换肤功能)
- 根据id去重_Person Re-ID研究综述
- python多线程和多进程——python并行编程实验
- 法拍房数量激增数百倍!来看看这里面的数据...
- android 魅族短信拦截,如何防护手机里的个人信息?魅族18系列教你如何防范隐私泄露...
- 轻松学Pytorch –车辆类型与颜色识别
- openstack虚拟机迁移操作
- 零基础程序员如何自学编程?用这6种方法就够了!
- dnf服务器炸团门票怎么找回,DNF:打团掉线被献祭点这里免费补门票,再也不怕被献祭没牌了...
- 摄影测量空间后方交会外方位元素的解算程序
- 浏览器无法访问百度的问题
- Windows11网速慢解决方案
- C/C++常用的文件函数注释格式
- VUE 项目更新部署时,浏览器页面缓存问题
- linux沙箱隔离_360隔离沙箱在WINDOWS 10 的WSL下的沙箱逃逸
- 六位不重复房间ID生成器,不使用Redis和额外数据结构
- AI智能写作将改变文学创作的未来?
- 程序员:被问“刚毕业吧”,憋一口老血如何回击?网友:不理睬!
- 《Applied Energy》期刊介绍(SCI 1区)