用户管理and权限管理

用户管理

1.创建一个用户xiebo,其ID号为2008, 基本组为xbgroup(组ID为3008),附加组为xblinux
groupadd -g  3008 xbgroup
groupadd xblinux
useradd -u 2008 -g xbgroup -G xblinux   xiebo

2. 创建一个用户 ubuntu,其全名为ubuntu community,默认shell为tcsh
useradd -c "ubuntu community" -s /bin/tcsh  ubuntu

3. 修改用户xiebo的ID号为4008,基本组为 xblinux,附加组为xbgroup和ubuntu
usermod -u 4008 -g xblinux -G xbgroup,ubuntu   xiebo

4.给用户ubuntu加密码,并设定其密码最短使用期限为2天,最长为50天
  passwd -n 2 -x 50  ubuntu 
   
5. 将用户xiebo的默认shell改为/bin/bash
usermod -s /bin/bash xiebo 

6.添加系统用户hbase,且不允许其登录系统
 useradd -r -s /sbin/nologin   hbase

7.新建一个没有家目录的用户openstack
   useradd -M   openstack

8.复制/etc/skel为home/openstack (相当于提供家目录)
   cp -r   /etc/skel    /home/openstack

9.改变/home/openstack及内部文件的属主属组均为openstack
  chown -R  openstack.openstack   /home/openstack

10./home/openstack及其内部的文件,属组和其他用户没有任何访问权限
   chmod   go=  /home/openstack


权限管理
1.chown  改变文件属主(管理员才有权限修改)
      eg:    chown  xiebo a.txt     将文件a.txt的属主改成用户xiebo
                 
chown  xiebo:xiebo   a.txt     将文件a.txt的属主改成用户xiebo,所属组改成xiebo
                 chown  -R    xiebo    /home/tmp     将文件路径/home/tmp下所有的文件及子文件下的文件改成用户xiebo
                 chown --reference=/path/to/somefile    filea     将文件filea的属主改成somefile文件的属主

2. chmod   修改文件的权限
 2.1修改三类用户的权限
      chmod  777   file
      chmod   --reference=/path/to/somefileb   filea     将文件filea的权限改成与fileb相同
  
 2.2  修改某类用户的权限 (a代表所有,u代表属组;g代表同组;o代表其他)
       chmod   u=rw,g=r    filea      将文件filea的属主权限改成读写,所属组权限改成读
       chmod   uo=rx     fileb           将文件fileab的属主和其他用户的权限改成读和执行权限

2.3  修改某类用户的权限
       chmod  u+x   filea    将文件filea的属主权限加上执行权限
       chmod   o-x   fileb    将文件fileb的其他用户的权限去掉执行权限
        chmod   -x    filec    将文件filec的执行权限去掉 


3。 umask   遮罩码
   创建一个文件的权限为  666-umask  (文件默认不能具有执行权限,如果算得的结果中有执行权限,则将其权限加1;)
   创建一个目录的权限为   777-umask

eg:如果umask为0002    创建文件的默认权限为666-002=664  
                                         创建目录的默认权限为777-002=775


4.shell的类型(站在用户的角度来说)
   4.1登录式shell: (正常通过某终端登录; su -  username  ;  su -l username)
   4.2非登录式shell: (su username;  图形终端下打开的命令窗口;自动执行的shell脚本)


5. bash的配置文件:
5.1全局配置:  /etc/profile,   /etc/profile.d/*.sh ,   /etc/bashrc
     个人配置:~/.bash_profile ,   ~/.bashrc

5.2  profile类的文件:  设定环境变量; 运行命令或脚本
       bashrc类的文件:  设定本地变量;  定义命令别名
 
5.3  登录式shell如何读取配置文件?
      /etc/profile  -->  /etc/profile.d/*.sh -->  ~/.bash_profile --> ~/.bashrc   -->   /etc/bashrc

        非登录式shell如何读取配置文件?
      ~/.bashrc  -->  /etc/bashrc  -->  /etc/profile.d/*.sh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值