#useradd命令:建立用户帐号和创建用户的起始目录,使用权限是超级用户
[[email protected]_168_102_centos ~]# useradd test [[email protected]_168_102_centos ~]# id test uid=502(test) gid=502(test) groups=502(test) [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test:x:502:502::/home/test:/bin/bash
useradd –u UID:创建用户时直接指定UID
[[email protected]_168_102_centos ~]# useradd -u 888 test_1 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test_1:x:888:888::/home/test_1:/bin/bash
useradd –g GID:创建用户时直接指定GID,GID要事先存在
[[email protected]_168_102_centos ~]# useradd -g 500 test_2 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test_2:x:889:500::/home/test_2:/bin/bash [[email protected]_168_102_centos ~]# id test_2 uid=889(test_2) gid=500(wanghan) groups=500(wanghan) [[email protected]_168_102_centos ~]# useradd -g 777 test_3 useradd: group ‘777‘ does not exist
useradd –G GID:创建用户时直接指定额外组,但组要事先存在
[[email protected]_168_102_centos ~]# useradd -G 500 test_3 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test_3:x:890:890::/home/test_3:/bin/bash [[email protected]_168_102_centos ~]# id test_3 uid=890(test_3) gid=890(test_3) groups=890(test_3),500(wanghan)
useradd –d:创建用户时指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录
[[email protected]_168_102_centos ~]# useradd -d /home/qidian -m test_6 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test_6:x:893:893::/home/qidian:/bin/bash [[email protected]_168_102_centos ~]# ls /home abc ceshi openstack qidian test test_1 test_2 test_3 wanghan
说明: –m:创建用户时,强制给用户创建主目录
useradd –M:创建用户,但不创建家目录
[[email protected]_168_102_centos ~]# ls /home abc ceshi openstack qidian test test_1 test_2 test_3 wanghan [[email protected]_168_102_centos ~]# useradd -M test_7 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test_7:x:895:895::/home/test_7:/bin/bash [[email protected]_168_102_centos ~]# ls /home abc ceshi openstack qidian test test_1 test_2 test_3 wanghan
useradd -c:创建用户指定一段注释性描述,在/etv/passwd中查看
[[email protected]_168_102_centos ~]# useradd -c wanghan test_9 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test_9:x:897:897:wanghan:/home/test_9:/bin/bash
useradd –s:创建用户时指定默认shell,应该指定/etc/shells文件出现的shell
[[email protected]_168_102_centos ~]# useradd -s tcsh test_10 useradd: invalid shell ‘tcsh‘ [[email protected]_168_102_centos ~]# useradd -s /bin/tcsh test_10 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test_10:x:898:898::/home/test_10:/bin/tcsh
#groupadd命令:创建一个新组
[[email protected]_168_102_centos ~]# groupadd hp [[email protected]_168_102_centos ~]# tail -n 1 /etc/group hp:x:2001:
groupadd –g GID:创建新组并指定GID
[[email protected]_168_102_centos ~]# groupadd -g 2000 wudi [[email protected]_168_102_centos ~]# tail -n 1 /etc/group wudi:x:2000: [[email protected]_168_102_centos ~]#
#userdel命令:删除用户,默认保留家目录
[[email protected]_168_102_centos ~]# userdel test_9 [[email protected]_168_102_centos ~]# tail /etc/passwd test_1:x:888:888::/home/test_1:/bin/bash test_2:x:889:500::/home/test_2:/bin/bash test_3:x:890:890::/home/test_3:/bin/bash test_4:x:891:891::/home/abc:/bin/bash openstack:x:892:892::/home/openstack:/bin/bash test_6:x:893:893::/home/qidian:/bin/bash wanghan11:x:894:894::/tmp/wanghan:/bin/bash test_7:x:895:895::/home/test_7:/bin/bash test_8:x:896:896::/home/test_8:/bin/bash test_10:x:898:898::/home/test_10:/bin/tcsh [[email protected]_168_102_centos ~]# ls /home abc ceshi openstack qidian test test_1 test_10 test_2 test_3 test_8 test_9 wanghan
userdel -r:删除用户同时删除其家目录
[[email protected]_168_102_centos ~]# userdel -r test_8 [[email protected]_168_102_centos ~]# tail /etc/passwd test:x:502:502::/home/test:/bin/bash test_1:x:888:888::/home/test_1:/bin/bash test_2:x:889:500::/home/test_2:/bin/bash test_3:x:890:890::/home/test_3:/bin/bash test_4:x:891:891::/home/abc:/bin/bash openstack:x:892:892::/home/openstack:/bin/bash test_6:x:893:893::/home/qidian:/bin/bash wanghan11:x:894:894::/tmp/wanghan:/bin/bash test_7:x:895:895::/home/test_7:/bin/bash test_10:x:898:898::/home/test_10:/bin/tcsh [[email protected]_168_102_centos ~]# ls /home abc ceshi openstack qidian test test_1 test_10 test_2 test_3 test_9 wanghan
#passwd命令:设定用户密码
管理员修改自身密码:
[[email protected]_168_102_centos ~]# passwd Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully.
管理员修改其他用户密码:
[[email protected]_168_102_centos ~]# passwd wanghan Changing password for user wanghan. New password: Retype new password: passwd: all authentication tokens updated successfully.
用户修改自身密码:
[[email protected]_168_102_centos rott]$ passwd Changing password for user wanghan. Changing password for wanghan. (current) UNIX password: //输入当前密码 New password: Retype new password: passwd: all authentication tokens updated successfully.
passwd –l:锁定用户密码,用户不能修改密码
[[email protected]_168_102_centos ~]# passwd -l wanghan Locking password for user wanghan. passwd: Success [[email protected]_168_102_centos ~]# su wanghan [[email protected]_168_102_centos rott]$ passwd Changing password for user wanghan. Changing password for wanghan. (current) UNIX password: passwd: Authentication token manipulation error
passwd –u:解除用户密码锁定
[[email protected]_168_102_centos ~]# passwd -u wanghan Unlocking password for user wanghan. passwd: Success [[email protected]_168_102_centos ~]# su wanghan [[email protected]_168_102_centos rott]$ passwd Changing password for user wanghan. Changing password for wanghan. (current) UNIX password: New password:
passwd –S:显示用户密码简要信息
[[email protected]_168_102_centos ~]# passwd -S wanghan wanghan PS 2014-08-12 0 99999 7 -1 (Password set, SHA512 crypt.)
#usermod命令:用来修改用户帐号的各项设定
usermod –u UID:修改用户UID
[[email protected]_168_102_centos ~]# id openstack uid=892(openstack) gid=892(openstack) groups=892(openstack) [[email protected]_168_102_centos ~]# usermod -u 588 openstack [[email protected]_168_102_centos ~]# id openstack uid=588(openstack) gid=892(openstack) groups=892(openstack)
usermod –g GID:修改用户GID
[[email protected]_168_102_centos ~]# id wanghan uid=500(wanghan) gid=2000(wudi) groups=2000(wudi) [[email protected]_168_102_centos ~]# usermod -g 2001 wanghan [[email protected]_168_102_centos ~]# id wanghan uid=500(wanghan) gid=2001(hp) groups=2001(hp)
usermod –G GID:修改用户附加组,默认覆盖原有附加组,同时使用-a选项则是再额外添加
[[email protected]_168_102_centos ~]# id user1 uid=899(user1) gid=899(user1) groups=899(user1),2000(wudi) [[email protected]_168_102_centos ~]# usermod -G 2001 user1 [[email protected]_168_102_centos ~]# id user1 uid=899(user1) gid=899(user1) groups=899(user1),2001(hp) [[email protected]_168_102_centos ~]# usermod -a -G 2000 user1 [[email protected]_168_102_centos ~]# id user1 uid=899(user1) gid=899(user1) groups=899(user1),2000(wudi),2001(hp)
usermod –c:修改用户帐号备注信息
[[email protected]_168_102_centos ~]# useradd -c hello user2 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd user2:x:900:900:hello:/home/user2:/bin/bash [[email protected]_168_102_centos ~]# usermod -c test user2 [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd user2:x:900:900:test:/home/user2:/bin/bash
usermod -d:修改用户家目录,默认不会迁移家目录,同时使用-m则可迁移
[[email protected]_168_102_centos ~]# usermod -d /tmp/wanghan user1 [[email protected]_168_102_centos ~]# tail /etc/passwd test_2:x:889:500::/home/test_2:/bin/bash test_3:x:890:890::/home/test_3:/bin/bash test_4:x:891:891::/home/abc:/bin/bash openstack:x:588:892::/home/openstack:/bin/bash test_6:x:893:893::/home/qidian:/bin/bash wanghan11:x:894:894::/tmp/wanghan:/bin/bash test_7:x:895:895::/home/test_7:/bin/bash test_10:x:898:898::/home/test_10:/bin/tcsh user1:x:899:899::/tmp/wanghan:/bin/bash user2:x:900:900:test:/home/user2:/bin/bash [[email protected]_168_102_centos ~]# usermod -d /tmp/user2/ -m user2 [[email protected]_168_102_centos ~]# tail /etc/passwd test_2:x:889:500::/home/test_2:/bin/bash test_3:x:890:890::/home/test_3:/bin/bash test_4:x:891:891::/home/abc:/bin/bash openstack:x:588:892::/home/openstack:/bin/bash test_6:x:893:893::/home/qidian:/bin/bash wanghan11:x:894:894::/tmp/wanghan:/bin/bash test_7:x:895:895::/home/test_7:/bin/bash test_10:x:898:898::/home/test_10:/bin/tcsh user1:x:899:899::/tmp/wanghan:/bin/bash user2:x:900:900:test:/tmp/user2/:/bin/bash
usermod –s:修改用户shell
linux学习命令总结⑦
时间: 2024-11-17 05:56:29