---
title: "我使用过的Linux命令之adduser - 添加用户账号"
author: "codingstandards"
date: "2010-09-29T16:04:26Z"
tags: ["Bash", "Blog", "Linux", "Oracle", "SSH"]
categories: ["操作系统"]
slug: "linux-adduser"
draft: false
lastmod: "2011-04-10T11:35:27Z"
id: 775194
url: "https://codingstandards.iteye.com/blog/775194"
---

# 我使用过的Linux命令之adduser - 添加用户账号

本文链接：[http://codingstandards.iteye.com/blog/775194](/blog/775194)    （转载请注明出处）

 

## 用途说明

添加用户，与useradd是同一命令。需要root权限才能执行（有root權限）。

## 常用参数

-d home\_dir 设定使用者的主目录为 home\_dir

-p passwd  指定用户的登录密码。RHEL4支持此参数，RHEL5已经去掉这个参数了。

-g group 指定用户所在的群组。

## 使用示例

### 示例一

\[root@localhost root]# adduser xxx  
\[root@localhost root]# ls -l /home/xxx  
total 0  
\[root@localhost root]# ls -ld /home/xxx  
drwx------    2 xxx      xxx          4096  9月 29 16:05 /home/xxx  
\[root@localhost root]# grep xxx /etc/passwd /etc/shadow /etc/group  
/etc/passwd:xxx:x:500:500::/home/xxx:/bin/bash  
/etc/shadow:xxx:!!:14881:0:99999:7:::  
/etc/group:xxx:x:500:  
\[root@localhost root]#        

\[root@localhost root]# ssh xxx@localhost  
xxx@localhost's password:  
Permission denied, please try again.  
xxx@localhost's password:  
Permission denied, please try again.  
xxx@localhost's password:  
Permission denied (publickey,password,keyboard-interactive).  
\[root@localhost root]#  
\[root@localhost root]#  
\[root@localhost root]# passwd xxx  
Changing password for user xxx.  
New password:  
BAD PASSWORD: it is too simplistic/systematic  
Retype new password:  
passwd: all authentication tokens updated successfully.  
\[root@localhost root]#  
\[root@localhost root]#  
\[root@localhost root]# ssh xxx@localhost  
xxx@localhost's password:  
\[xxx@localhost xxx]$

### 示例二

\[root@localhost root]# adduser -d /opt/oracle oracle  
\[root@localhost root]# ls -ld /opt/oracle  
drwx------    2 oracle   oracle       1024  9月 29 16:10 /opt/oracle  
\[root@localhost root]# grep oracle /etc/passwd /etc/shadow /etc/group  
/etc/passwd:oracle:x:501:501::/opt/oracle:/bin/bash  
/etc/shadow:oracle:!!:14881:0:99999:7:::  
/etc/group:oracle:x:501:  
\[root@localhost root]#

## 问题思考

1\. 怎样添加一个系统管理员账号，与root权限相同？

2\. 怎样禁止账号登录？

3\. 怎样对账号设置期限？

4\. 怎么知道系统中有哪些可用账号？

## 相关资料

【1】风雨林的Blog [Linux adduser命令格式](http://blog.chinaunix.net/u1/59646/showart_465892.html)

【2】Linux man page [adduser](http://linux.die.net/man/8/adduser)

【3】wljcz.com网络教程站 [Linux adduser添加用户](http://www.wljcz.com/html/caozuoxitong/Linux/2009/0801/561.html)

 

 

返回 [我使用过的Linux命令系列总目录](/blog/786653)