Linux系统手动添加创建用户的步骤

发表时间:2015-10-09 14:34 | 分类:Linux | 浏览:2,464 次

linux中我们通常使用useradd或者adduser命令来添加用户。了解了用户、组、密码几个文件后,当然也可以手动创建。例如我们需要创建用户hive,他的基本组为hive,用户和组的uid、gid都是5000,hive附加组为user1,密码为sijitao.net 。假设附加组user1已经存在。

第一步:添加组

编辑/etc/group,在文件的末尾添加“hive:x:5000:”,且修改user1组,添加hive用户为附加组。修改后的group文件类似如下:

zhangnq:x:500:
py27:x:501:
user1:x:502:hive
hive:x:5000:

第二步:添加用户

编辑/etc/passwd,在文件末尾添加“hive:x:5000:5000:Hive:/home/hive:/bin/bash”,分别表示“用户名:密码占位符:用户uid:基本组gid:全称:家目录:shell”。

编辑/etc/shadow密码文件,在末尾添加“hive:!!:16717:0:99999:7:::”,分别表示“用户名:!!表示空密码:上次修改密码时间,从1970-01-01到现在过去天数:密码最短使用时间:密码最长使用时间:7警告时间:::”。

第三步:创建家目录

[root@localhost etc]# cp -r /etc/skel/ /home/hive
[root@localhost etc]# chown -R hive:hive /home/hive
[root@localhost etc]# chmod -R go= /home/hive
[root@localhost etc]# ls -ld /home/hive/
drwx------. 4 hive hive 4096 Oct 9 13:17 /home/hive/
[root@localhost etc]# ls -la /home/hive/
total 28
drwx------. 4 hive hive 4096 Oct 9 13:17 .
drwxr-xr-x. 6 root root 4096 Oct 9 13:17 ..
-rw-------. 1 hive hive 18 Oct 9 13:17 .bash_logout
-rw-------. 1 hive hive 176 Oct 9 13:17 .bash_profile
-rw-------. 1 hive hive 124 Oct 9 13:17 .bashrc
drwx------. 2 hive hive 4096 Oct 9 13:17 .gnome2
drwx------. 4 hive hive 4096 Oct 9 13:17 .mozilla

到这一步用户hive就创建好了,我们可以使用su切换到该用户,不过用户为空密码。

[root@localhost etc]# su - hive
[hive@localhost ~]$ id
uid=5000(hive) gid=5000(hive) groups=5000(hive),502(user1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

第四步:创建密码

先用openssl创建一个md5格式的密码,salt后面跟上任意八位字符即可。

[root@localhost etc]# openssl passwd -1 -salt '12345678'
Password: 
$1$12345678$BZfbae53xOvLXWuWwUag8/

得到密码字符串,复制,修改/etc/shadow密码文件中的两个!! 。

hive:$1$12345678$BZfbae53xOvLXWuWwUag8/:16717:0:99999:7:::

到这一步结束,linux中手动创建用户hive就好了。

本文标签:

本文链接:https://www.sijitao.net/2062.html

欢迎您在本博客中留下评论,如需转载原创文章请注明出处,谢谢!

已经有6个回复
Comment (6)
Trackbacks (0)
  1. 大学问社区  ( 2015.10.10 10:42 ) : #-9

    :twisted: 干货

  2. 安安博客  ( 2015.10.10 21:49 ) : #-8

    一点都看不懂哇

  3. 大学问社区  ( 2015.10.12 10:56 ) : #-7

    木更啊 :cry:

    • 章郎虫  ( 2015.10.12 15:56 ) :

      什么意思?更新?

  1. 还没有Trackbacks
一键脚本 博客历程 留言联系 文章归档 网站地图 谷歌地图
Copyright © 2010-2024 章郎虫博客 All Rights Reserved.