Linux创建用户和密码相关的命令useradd、groupadd、passwd和userdel应用
admin
2024-02-25 01:36:44
0次

记录:351

场景:在CentOS 7.9操作系统上,使用useradd命令创建用户;使用groupadd命令创建用户组;使用passwd命令修改密码、锁定密码、设置密码有效时间等;使用userdel删除用户。

版本:

操作系统:CentOS 7.9

1.groupadd命令应用

(1)创建用户组

命令:groupadd hangzhou

解析:创建一个用户组,名称为hangzhou。

(2)强制创建用户组

命令:groupadd -f hangzhou

解析:创建一个用户组,名称为hangzhou;-f,强制创建。

2.useradd命令应用

(1)创建用户

命令:useradd hangzhou

解析:创建一个用户,hangzhou是用户名。

(2)创建用户

命令:useradd -g hangzhou hangzhou -d /home/hangzhou

解析:创建一个用户,-g hangzhou,指定用户组是hangzhou;第二个hangzhou是用户名;-d,指定创建用户的home目录。

(3)创建用户

命令:useradd -g hangzhou xihu -d /home/xihu

解析:创建一个用户,-g hangzhou,指定用户组是hangzhou;xihu是用户名;-d,指定创建用户的home目录。在hangzhou用户组下创建了两个用户。

(4)创建用户不创建home目录

命令:useradd zhejiang -M

解析:创建用户,没有home目录。

(5)创建系统用户

命令:useradd -r binjiang

解析:创建系统用户,没有home目录,系统用户序号在1000以内,普通用户从1000开始。

3.passwd命令应用

(1)修改密码

命令格式:passwd 用户名

命令:passwd hangzhou

解析:执行命令时,命令行提示New password:,然后输入密码就行。

(2)强制修改密码(-f选项)

命令:passwd -f hangzhou

解析:强制修改密码;执行命令时,命令行提示New password:,然后输入密码就行。

(3)从输入流修改密码

命令:passwd -stdin hangzhou

解析:这种方式修密码,能看到输入字符串,其它方式修改密码是看不到输入的字符串。

(4)删除密码

命令:passwd -d hangzhou

解析:删除指定用户的密码,只能是root用户操作。

(5)锁定密码

命令:passwd -l hangzhou

解析:锁定指定用户的密码,只能是root用户操作。

(6)解锁密码

命令:passwd -u hangzhou

解析:解锁指定用户的密码,只能是root用户操作。

(7)设置密码失效

命令:passwd -e hangzhou

解析:设置指定用户的密码,只能是root用户操作。

(8)查看密码状态

命令:passwd -S hangzhou

解析:查看指定用户的密码状态,只能是root用户操作。

默认状态:hangzhou PS 1970-01-01 0 99999 7 -1 (Password set, SHA512 crypt.)

解析:从1970-01-01开始,99999天。

(9)设置密码最大有效时间

命令:passwd -x 30 hangzhou

解析:设置密码最大有效时间,只能是root用户操作。

查看状态:passwd -S hangzhou

状态信息:hangzhou PS 2022-11-28 0 30 7 -1 (Password set, SHA512 crypt.)

(10)设置密码生效开始时间

命令:passwd -n 3 hangzhou

解析:设置密码生效开始时间,只能是root用户操作。

查看状态:passwd -S hangzhou

状态信息:hangzhou PS 2022-11-28 3 30 7 -1 (Password set, SHA512 crypt.)

解析:从设置时间开始3天后才有效。

(11)设置密码到期警告时间

命令:passwd -w 5 hangzhou

解析:设置密码到期前5天提示警告修改密码,只能是root用户操作。

查看状态:passwd -S hangzhou

状态信息:hangzhou PS 2022-11-28 3 30 5 -1 (Password set, SHA512 crypt.)

解析:密码到期前5天会开始提示修改密码。

(12)设置帐户被禁用时密码过期后的天数

命令:passwd -i 6 hangzhou

解析:设置密码生效开始时间,只能是root用户操作。

查看状态:passwd -S hangzhou

状态信息:hangzhou PS 2022-11-28 3 30 5 6 (Password set, SHA512 crypt.)

解析:帐户被禁用时密码过期后的天数。

(13)保留未过期的身份验证令牌

命令:passwd -k hangzhou

解析:保留未过期的身份验证令牌。

4.userdel命令

(1)删除用户

命令:userdel hangzhou

解析:删除用户。

(2)删除用户包括home目录

命令:userdel -r hangzhou

解析:删除用户,删除对应home目录。

5.查看用户和密码

(1)查看group文件

查看用户组:cat /etc/group | grep hangzhou

解析:使用cat和grep查看已经创建的用户组。

(2)查看passwd文件

查看用户和密码:cat /etc/passwd

查看用户和密码:cat /etc/passwd | grep xihu

解析:使用cat和grep查看已经创建的用户组。

6.命令帮助手册

(1)groupadd命令帮助手册

命令:groupadd --help

解析:查看groupadd支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

Usage: groupadd [options] GROUPOptions:-f, --force                   exit successfully if the group already exists,and cancel -g if the GID is already used-g, --gid GID                 use GID for the new group-h, --help                    display this help message and exit-K, --key KEY=VALUE           override /etc/login.defs defaults-o, --non-unique              allow to create groups with duplicate(non-unique) GID-p, --password PASSWORD       use this encrypted password for the new group-r, --system                  create a system account-R, --root CHROOT_DIR         directory to chroot into-P, --prefix PREFIX_DIR       directory prefix

(2)useradd命令帮助手册

命令:useradd --help

解析:查看useradd支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

Usage: useradd [options] LOGINuseradd -Duseradd -D [options]Options:-b, --base-dir BASE_DIR       base directory for the home directory of thenew account-c, --comment COMMENT         GECOS field of the new account-d, --home-dir HOME_DIR       home directory of the new account-D, --defaults                print or change default useradd configuration-e, --expiredate EXPIRE_DATE  expiration date of the new account-f, --inactive INACTIVE       password inactivity period of the new account-g, --gid GROUP               name or ID of the primary group of the newaccount-G, --groups GROUPS           list of supplementary groups of the newaccount-h, --help                    display this help message and exit-k, --skel SKEL_DIR           use this alternative skeleton directory-K, --key KEY=VALUE           override /etc/login.defs defaults-l, --no-log-init             do not add the user to the lastlog andfaillog databases-m, --create-home             create the user's home directory-M, --no-create-home          do not create the user's home directory-N, --no-user-group           do not create a group with the same name asthe user-o, --non-unique              allow to create users with duplicate(non-unique) UID-p, --password PASSWORD       encrypted password of the new account-r, --system                  create a system account-R, --root CHROOT_DIR         directory to chroot into-P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files-s, --shell SHELL             login shell of the new account-u, --uid UID                 user ID of the new account-U, --user-group              create a group with the same name as the user-Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping

(3)passwd命令帮助手册

命令:passwd --help

解析:查看passwd支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

Usage: passwd [OPTION...] -k, --keep-tokens       keep non-expired authentication tokens-d, --delete            delete the password for the named account (root only)-l, --lock              lock the password for the named account (root only)-u, --unlock            unlock the password for the named account (root only)-e, --expire            expire the password for the named account (root only)-f, --force             force operation-x, --maximum=DAYS      maximum password lifetime (root only)-n, --minimum=DAYS      minimum password lifetime (root only)-w, --warning=DAYS      number of days warning users receives before password expiration (root only)-i, --inactive=DAYS     number of days after password expiration when an account becomes disabled (root only)-S, --status            report password status on the named account (root only)--stdin                 read new tokens from stdin (root only)Help options:-?, --help              Show this help message--usage                 Display brief usage message

(4)userdel命令帮助手册

命令:userdel --help

解析:查看userdel支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

Usage: userdel [options] LOGINOptions:-f, --force                   force some actions that would fail otherwisee.g. removal of user still logged inor files, even if not owned by the user-h, --help                    display this help message and exit-r, --remove                  remove home directory and mail spool-R, --root CHROOT_DIR         directory to chroot into-P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files-Z, --selinux-user            remove any SELinux user mapping for the user

以上,感谢。

2022年11月28日

相关内容

热门资讯

蜻蜓订购APP贵金属订购非法期...   蜻蜓订购APP以"投资平台"名义对外宣传,主打贵金属期货(订购)交易。该平台一方面强调自身"正规...
悟空订购APP非法期货交易欺骗...   近期,有投资者反映,“悟空订购APP”等平台以白银、贵金属订购为名,宣传所谓“高收益”“低门槛”...
小赢淘金APP期货投资骗局,平...   “小赢淘金”之流,最擅长的就是用“注册送现金”、“充值返券”的糖衣炮弹来引流。别天真地以为那是福...
八方淘金APP非法期货交易欺骗...   警惕!八方生财、每日淘金、小赢淘金、悟空订购、蜻蜓订购、斗金订购等APP均涉嫌非法期货交易!  ...
智易购APP贵金属订购交易骗局...   很多人看到“3元起投”“充值送福利”“操作简单”“随时提现”这类宣传,很容易把智易购APP当成普...
喜玛银庄APP商品订购投资骗局...   喜玛银庄APP白银、铂金“现货订购”骗局警示:无资质平台涉嫌非法期货交易,投资者爆仓后如何维权?...
吉鑫乐享APP炒贵金属订购交易...   近期,多名投资者反映在“吉鑫乐享APP”进行贵金属投资时遭遇严重亏损,甚至血本无归。看似正规的“...
易掘金APP虚假期货投资骗局,...   “易掘金”的APP它打着“高收益、灵活投资”的旗号,宣称通过“商品订购”就能轻松赚钱,吸引了不少...
在大吉订购APP订购交易亏损被...   近期,不少投资者反映在“大吉订购App”上投资白银、铂金等商品遭遇严重亏损。该平台宣称提供现货订...
铂银壹号APP商品订购交易亏损...   许多中小投资者误以为网上的“商品现货订购”是合规合法的理财渠道,殊不知这背后隐藏着巨大的合规风险...
兴鑫淘金APP贵金属订购交易亏...   白银、贵金属或其他商品类投资,除国家批准的正规期货交易场所及持牌期货公司外,市面上大量第三方交易...
铂银掘金APP无资质的违规平台...   铂银掘金等平台的投资者,往往是被“注册送现金”“充值返现券”“首单免亏”等广告话术吸引,进而下载...
八方淘金APP订购交易不合规,...   “八方淘金APP”“铂银掘金APP”“铂银壹号APP”等软件被指以“现货订购”为名,实际采用高杠...
在指尖订购APP订购商品亏损被...   指尖订购APP这类平台,表面是“订购交易”,实则是披着电商外衣的非法期货陷阱。绝大多数投资者被蒙...
在犀贝易购APP做商品订购交易...   市面上打着“现货投资”“贵金属交易”旗号的APP并不少,但真正合规、受监管的平台并不多。犀贝易购...
易达淘金APP虚假商品订购交易...   易达淘金APP存在严重的虚假宣传与违规交易行为。该平台打着“商品订购”的旗号,实则通过不合规的交...
大浪淘金APP白银订购亏损被骗...   大浪淘金APP最隐蔽的套路,在于其完全封闭的内盘交易系统。表面上,它宣称与国际贵金属市场接轨;实...
一品好购APP上订购白银出现亏...   一品好购APP原名“一品订购”,运营方为上海宝智未来信息技术有限公司。近期不少投资者反映在该平台...
九州订购APP贵金属订购投资骗...   九州订购APP正通过抖.音、快手、今日头条等平台大量投放投资广告,用“5元起投”“充值返现”“0...
坚锅淘金APP交易软件并不正规...   当前,市面上大量所谓的“现货商城订购”交易软件,早已偏离了正常的实物商品买卖,演变为高杠杆、高手...