Chinaunix首页 | 论坛 | 博客
  • 博客访问: 693678
  • 博文数量: 112
  • 博客积分: 3889
  • 博客等级: 少校
  • 技术积分: 1448
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-19 16:35
个人简介

追求卓越,成功就会在不经意间追上你

文章分类

全部博文(112)

文章存档

2015年(1)

2014年(2)

2013年(1)

2012年(16)

2011年(86)

2010年(6)

分类: Python/Ruby

2011-07-25 20:32:24

手动添加用户 #root用户下

1.编辑/etc/passwd,/etc/shadow文件

可以使用vim或其它任何你忠爱的文本编辑器编辑相关文件。这里还有一个用特别来编辑passwd文件的东东,vipw每次只允许一个人编辑/etc/passwd文件;编辑时打开的是/etc/passwd的一个副本,操作完成后会用相应的副本来替换原来的passwd文件。

下面,我们添加一个用户test;在/etc/passwd最后加入一行:

test:x:555:555:Just a test,take it easy:/home/test:/bin/bash

编辑/etc/shadow,在最后一行加入:

test:*::::::30:

#如果使用vipw的话,在编辑完/etc/passwd后会询问你是否接着编辑/etc/shadow文件,选择y继续编辑/etc/shadow

[root@kingdom ~]# vipw

You are using shadow passwords on this system.Would you like to edit /etc/shadow now [y/n]? y

 

#记得要保存离开。

 

 

2.编辑/etc/group文件

/etc/group中给用户test建立个人的用户组,仍命名为test

/etc/group添加如下信息:

[root@kingdom ~]# vim /etc/group

test::555:test

 

 

3.设置口令

使用passwd命令.root能用passwd命令修改任何用户的password;您也可以使用sudo passwd来更改相关用户口令;现在我们为test设置一个口令:

[root@kingdom ~]# passwd test

Changing password for user test.

New UNIX password:

BAD PASSWORD: it is too short

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

[root@kingdom ~]#

#口令会被要求输入两次,而linux也会自动检查相应口令的复杂程度然后给出相应的提示,如上面的BAD PASSWORD: it is too short;当然,你可以完全忽视它!

#为了您和您系统的安全,请一定要设置好口令!

 

4.创建用户主目录

系统管理员创建的任何目录最初都归root所有,所以……你懂的!

下面为test创建一个家目录:

[root@kingdom ~]# mkdir /home/test

[root@kingdom ~]# chown test:test /home/test

[root@kingdom ~]# chmod 700 /home/test

[root@kingdom ~]# ls -l /home

total 12

drwx------ 22 centos centos 4096 Jul 24 22:00 centos

drwx------  2 test   test   4096 Jul 24 22:34 test

5.复制默认启动文件

/etc/skel下存放着新建用户用到的默认文件,我们把这里面的文件全部复制到test的家目录下,记得要修改权限喔!


 

[root@kingdom ~]#cp /etc/skel/.* /home/test

[root@kingdom ~]# ls -al /home/test

total 32

drwx------ 3 test test 4096 Jul 24 23:25 .

drwxr-xr-x 4 root root 4096 Jul 24 23:18 ..

-rw------- 1 test test   76 Jul 24 23:23 .bash_history

-rw-r--r-- 1 root root   33 Jul 24 23:23 .bash_logout

-rw-r--r-- 1 root root  176 Jul 24 23:23 .bash_profile

-rw-r--r-- 1 root root  124 Jul 24 23:23 .bashrc

drwxr-xr-x 4 root root 4096 Jul 24 23:23 .mozilla

 

6.设置用户邮件主目录

 [root@kingdom ~]# mkdir /var/mail/test

[root@kingdom ~]# chown test:mail /var/mail/test

[root@kingdom /]# ls -l /var/mail/

total 28

-rw-rw---- 1 centos mail     0 Apr 24 12:58 centos

-rw------- 1 root   root 13284 Jul 24 22:53 root

-rw-rw---- 1 rpc    mail     0 Apr 24 12:42 rpc

drwxr-xr-x 2 test   mail  4096 Jul 25 20:27 test

 

7.验证

[root@kingdom /]# su test

[test@kingdom /]$ whoami

test

#添加成功!

阅读(1319) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~