useradd具体参数

[root@yhwang ~] useradd -h
Usage: useradd [options] LOGIN
useradd -D
useradd -D [options] Options:
-b, --base-dir BASE_DIR base directory for the home directory of the
new 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 new
account
-G, --groups GROUPS list of supplementary groups of the new
account
-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 and
faillog 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 as
the 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
-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

useradd创建的账户的默认值

[root@yhwang ~]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

  1)新用户添加到GID为100的公共组
  2)新用户的HOME目录将会位于/home/username
  3)新用户账户密码在过期后不会被禁用
  4)新用户账户未被设置为某个日期后就过期
  5)新用户账户将bash shell作为默认shell
  6)系统会将/etc/skel目录下的内容复制到用户的HOME目录下
  7)系统为该用户账户在mail目录下创建一个用于接收邮件的文件

userdel具体参数

[root@yhwang ~]# userdel -h
Usage: userdel [options] LOGIN Options:
-f, --force force some actions that would fail otherwise
e.g. removal of user still logged in
or 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
-Z, --selinux-user remove any SELinux user mapping for the user

useradd添加账户和userdel删除账户

[root@yhwang ~]# useradd tom
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists
[root@yhwang ~]# tail -1 /etc/passwd
tom:x:500:500::/home/tom:/bin/bash
[root@yhwang ~]# userdel -r tom
[root@yhwang ~]# useradd tom
[root@yhwang ~]# tail -1 /etc/passwd
tom:x:500:500::/home/tom:/bin/bash

passwd具体参数

[root@yhwang ~]# passwd --help
Usage: passwd [OPTION...] <accountName>
-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

passwd设置修改账户密码

[root@yhwang ~]# passwd tom
Changing password for user tom.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully. [root@yhwang ~]# echo "tom"|passwd --stdin tom
Changing password for user tom.
passwd: all authentication tokens updated successfully.

赋予root权限

方法一

修改 /etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉

## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL

然后修改用户,使其属于root组(wheel),命令如下:

[root@yhwang ~] usermod -g root tom

修改完毕,现在可以用tom帐号登录,然后用命令 su - ,即可获得root权限进行操作。

方法二

修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
tom ALL=(ALL) ALL

修改完毕,现在可以用tom帐号登录,然后用命令 su - ,即可获得root权限进行操作。

方法三

修改 /etc/passwd 文件,找到如下行,把用户ID修改为 0 ,如下所示:

## 修改前

tom:x:500:500:tom:/home/tom:/bin/bash

## 修改后

tom:x:0:500:tom:/home/tom:/bin/bash

保存,用tom账户登录后,直接获取的就是root帐号的权限。

参考资料

http://www.centoscn.com/CentOS/config/2014/0810/3471.html

Centos下添加/删除用户的更多相关文章

  1. CentOS下添加sudo用户

    一 .sodo的使用 1.1 关于sudo Sudo是linux系统中,非root权限的用户提升自己权限来执行某些特性命令的方式,它使普通用户在不知道超级用户的密码的情况下,也可以暂时的获得root权 ...

  2. Linux——CentOS7添加/删除用户和用户组1

    Linux--CentOS7添加/删除用户和用户组 2017.05.02 19:58 23012浏览   前言 今天又重新装了centos7突然有关用户和用户组有关的命令记不清了,所以记一下,也方便你 ...

  3. centos的用户、组权限、添加删除用户等操作的详细操作命令

    1.Linux操作系统是多用户多任务操作系统,包括用户账户和组账户两种 细分用户账户(普通用户账户,超级用户账户)除了用户账户以为还 有组账户所谓组账户就是用户账户的集合,centos组中有两种类型, ...

  4. [CentOS]添加删除用户

    摘要 在安装CentOS的时候,我们只设置了root,类似windows的超级管理员.当然我们在工作的时候,为了安全考虑,不可能对外开发root,一方面是从安全的角度,另一方面也是方便管理. 添加删除 ...

  5. 嵌入式环境:CentOS下添加用户并且让用户获得root权限

    CentOS下添加用户并且让用户获得root权限 http://www.centoscn.com/CentOS/config/2014/0810/3471.html 1.添加用户,首先用adduser ...

  6. Centos 下添加开机自启动服务和脚本【转】

    最近刚玩Centos7的系统,跟Centos6还是很多方面有改变的,这里记录一下怎么在Centos7下添加开机自启动脚本和服务的方法. 1.添加开机自启服务 我这里以docker 服务为例,设置如下两 ...

  7. vue简单案例_动态添加删除用户数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 详解centos用户&组权限&添加删除用户

    1.Linux用户操作系统 Linux操作系统是多用户多任务操作系统,包括用户账户和组账户两种: 细分用户账户(普通用户账户,超级用户账户)除了用户账户以为还有组账户所谓组账户就是用户账户的集合,ce ...

  9. linux下添加删除,修改,查看用户和用户组

    一.组操作 1.创建组: groupadd test #增加一个test组 2.修改组 groupmod -n test2 test #将test组的名子改成test2 3.删除组 groupdel ...

随机推荐

  1. Html标签使用——文字、列表、表格、超链接

    注:文章来源于传智播客毕向东老师使用课件和网络.整理学习如下: 一.Html内容 1.   Html就是超文本标记语言的简写,是最基础的网页语言. 2.   Html是通过标签来定义的语言,代码都是由 ...

  2. VC2010编译时提示:转换到 COFF 期间失败: 文件无效或损坏

    有时候新安装好VS2010后编译时就提示上述错误,罗列一下从网上查找到的几种解决方案: 方案1: 点击“项目”-->“属性”--> “清单工具”, 然后选择"输入和输出’--&g ...

  3. RabbitMQ点对点的模式

    1.点对点模式  一对一模式.  一个生产者投递消息给队列 只能允许有一个消费者进行消费    如果集群的话 会进行均摊消费   服务器配置不一样 均摊就不优了 长连接 不用三次握手之类的 提高传输效 ...

  4. 剑指offer之 替换空格

    package Problem4; public class ReplaceBank { /* * 题目描述: 请实现一个函数,将字符串的每个空格替换为"%20". * 例如输入& ...

  5. linux 下载rpm包到本地,createrepo:创建本地YUM源

    如何下载rpm包到本地 设置yum安装时,保留rpm包. 1.编辑 /etc/yum.conf 将keepcache的值设置为1; 这样就可以将yum安装时的rpm包保存在 /var/cache/yu ...

  6. spring 4 + jpa(hibernate 3/4) + spring mvc 多数据源配置

    先从persistence.xml开始: <?xml version=”1.0″ encoding=”UTF-8″?><persistence version=”2.1″ xmlns ...

  7. Python基础-常用模块OS

    模块:一个python文件就是一个模块,模块分三种: 1,标准模块,也就是python自带的模块,例如import  time,random,string等等 2,第三方模块,这种模块需要自己安装才能 ...

  8. Mex混合编程专题二:MEX Hello Word

    VS2010中写mex入门级工程代码 接着上一篇文章的工程继续,如下代码: #include "stdafx.h" #include "mextest.h" # ...

  9. 数据库连接池(connection pool)

    1.JDBC数据库连接池的必要性  在使用开发基于数据库的web程序时,传统的模式基本是按以下步骤: –      在主程序(如servlet.beans)中建立数据库连接. –      进行sql ...

  10. freeMarker(十)——模板语言之内建函数

    学习笔记,选自freeMarker中文文档,译自 Email: ddekany at users.sourceforge.net 1.字符串内建函数 这些内建函数作用于表达式左侧的字符串值. 如果左侧 ...