Ubuntu新建用户

新建用户的命令是useradd,修改密码是passwd,如下:

 

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. sudo useradd linc  
  2.   
  3. sudo passwd linc  


但是问题出现了,home目录下并没有相对应的linc目录。

 

原来ubuntu并没有为我们做那么多,先来看看useradd的选项:

 

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. 选项:  
  2.   -b, --base-dir BASE_DIR   新账户的主目录的基目录  
  3.   -c, --comment COMMENT         新账户的 GECOS 字段  
  4.   -d, --home-dir HOME_DIR       新账户的主目录  
  5.   -D, --defaults        显示或更改默认的 useradd 配置  
  6.   -e, --expiredate EXPIRE_DATE  新账户的过期日期  
  7.   -f, --inactive INACTIVE       新账户的密码不活动期  
  8.   -g, --gid GROUP       新账户主组的名称或 ID  
  9.   -G, --groups GROUPS   新账户的附加组列表  
  10.   -h, --help                    显示此帮助信息并推出  
  11.   -k, --skel SKEL_DIR   使用此目录作为骨架目录  
  12.   -K, --key KEY=VALUE           不使用 /etc/login.defs 中的默认值  
  13.   -l, --no-log-init 不要将此用户添加到最近登录和登录失败数据库  
  14.   -m, --create-home 创建用户的主目录  
  15.   -M, --no-create-home      不创建用户的主目录  
  16.   -N, --no-user-group   不创建同名的组  
  17.   -o, --non-unique      允许使用重复的 UID 创建用户  
  18.   -p, --password PASSWORD       加密后的新账户密码  
  19.   -r, --system                  创建一个系统账户  
  20.   -s, --shell SHELL     新账户的登录 shell  
  21.   -u, --uid UID         新账户的用户 ID  
  22.   -U, --user-group      创建与用户同名的组  
  23.   -Z, --selinux-user SEUSER     为 SELinux 用户映射使用指定 SEUSER  


我们需要自己来建一个用户的主目录和shell,如下:

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. userdel -r linc  
  2.   
  3. useradd linc -m -s /bin/bash  


再此设置好密码后,就可以切换用户了,su linc。

 

用exit也可以退出这个用户到默认用户。

 

ubuntu中查看所有的用户信息

$ cat /etc/passwd

 

All fields are separated by a colon (:) symbol. Total seven fields exists. The first field is username. It is used when user logs in. It should be between 1 and 32 characters in length

you can also  list only usernames with command awk , type these command in terminal :


awk -F':' '{ print $1}' /etc/passwd

root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
.....
.....

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值