zoukankan      html  css  js  c++  java
  • linux用户的增删改查(useradd/id/usermod/userdel)

    与用户(user)相关的配置文件;

     /etc/passwd 注:用户(user)的配置文件;

    /etc/shadow 注:用户(user)影子口令文件;


    与用户组(
    group)相关的配置文件;

     /etc/group 注:用户组(group)配置文件;

    /etc/gshadow 注:用户组(group)的影子文件;


    查看用户:
    cat /etc/passwd 或者id  user_name

     [root@localhost test]# cat /etc/passwd

    id user_name  ---查看特定用户

    [root@localhost test]# id lbg

    uid=1000(lbg) gid=1000(lbg) groups=1000(lbg)

    添加用户:useradd 

     -u:指定用户id

    -g:指定用户所属的群组

    -G:指定用户所属的附加群组

    -c:说明(comment

    -d:指定用户家目录

    -s:指定用户登入后所使用的shell

    -e:指定帐号的有效期限

    -f:指定在密码过期后多少天即关闭该帐号

    -m:自动建立用户的登入目录

    -M:不要自动建立用户的登入目录

    -n:取消建立以用户名称为名的群组

    -r:建立系统帐号

    说明:账户不设置初始密码是不能登录的.  普通账户自己不能给自己设置初始密码

    添加用户示例:

     [root@localhost test]# useradd -u 1001 test

    [root@localhost test]# id test

    uid=1001(test) gid=1001(test) groups=1001(test)


    使用用户:
    su - user_name

    用户登录的前提是必须有密码。

    给用户指定密码:passwd user_name

    只有root用户可以给其他用户设定密码。

    权利下行和权利上行:由root切换到其他用户,是权利下行,无需输入密码。由其他用户切换大root,是权利上行,需输入密码。

    注意su  - user_name  实际是 su -l user_name 的缩写.(-l   login).

    su与su-的区别:

    不加-,则进入后为原用户所在路径.加了-,则进入该用户的家目录.

    su 不加-,之前的环境变量不变,依旧可用.普通变量susu -  后都不可用.

    su 加-,之前的环境变量和普通变量都不可用。

    修改用户:usermod

     usermod -l,-u,-g,-d,-s

    -l是指login ,修改用户名(登录名). -d 家目录.  -s shell  -G 附属组.

    [root@localhost test]# usermod -l hello test        ---将用户test修改为hello.但组名不变。

    [root@localhost test]# id hello

    uid=1001(hello) gid=1001(test) groups=1001(test)

    /etc/passwd中为:hello:x:1001:1001::/home/test:/bin/bash      


    删除用户:
    userdel -rrremove

     [root@localhost test]# userdel -r hello      ---删除hello用户。

    注意若不加-r.则删除用户后,该用户的家目录和/var/spool/mail/user_name仍然存在。


     

  • 相关阅读:
    Redis源代码分析(十三)--- redis-benchmark性能測试
    kvm中运行kvm
    umount.nfs device busy day virsh extend diskSpace, attachDisk
    ultravnc
    openNebula dubug
    maintenance ShellScripts
    virsh VMI deploy data serial xml
    cloud computing platform,virtual authentication encryption
    基于C 的libvirt 接口调用
    storage theory
  • 原文地址:https://www.cnblogs.com/lbg-database/p/10109986.html
Copyright © 2011-2022 走看看