Linux 命令整理 —— 用户管理
Linux用户管理以读、写、执行动作为权限,以用户组为单位,限制用户行为。对于文件的的操作,可以限制读、写、执行中的哪一种,也可以限制文件所有者、组用户、组外用户相应的权限。
所以,要建立用户,最好先确定其所在的组。
一、用户组操作
1. 创建用户组——groupadd
#新增deploy组
groupadd deploy
2. 修改用户组——groupmod
#将用户组deploy更名为deploy1
groupmod -n deploy1 deploy
注意是将已存在的deploy组更名为deploy1
3. 删除用户组——groupdel
#删除用户组deploy1
groupdel deploy1
4. 查看用户组——groups /etc/group
groups只能查看当前用户所在的组,以下是root用户所在的组。
# groups
root bin daemon sys adm disk wheel
要看所有用户组信息,直接查看/etc/group:
# cat /etc/group
root:x::root
bin:x::root,bin,daemon
daemon:x::root,bin,daemon
sys:x::root,bin,adm
二、用户操作
1. 创建用户——useradd
# useradd
Usage: useradd [options] LOGIN Options:
-b, --base-dir BASE_DIR base directory for the new user account
home directory
-c, --comment COMMENT set the GECOS field for the new user account
-d, --home-dir HOME_DIR home directory for the new user account
-D, --defaults print or save modified default useradd
configuration
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP for the new user account
-G, --groups GROUPS list of supplementary groups for the new
user account
-h, --help display this help message and exit
-k, --skel SKEL_DIR specify an alternative skel directory
-K, --key KEY=VALUE overrides /etc/login.defs defaults
-m, --create-home create home directory for the new user
account
-l, do not add user to lastlog database file
-M, do not create user's home directory(overrides /etc/login.defs)
-r, create system account
-o, --non-unique allow create user with duplicate
(non-unique) UID
-p, --password PASSWORD use encrypted password for the new user
account
-s, --shell SHELL the login shell for the new user account
-u, --uid UID force use the UID for the new user account
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
新建用户deploy,位于deploy组,用于部署工作:
#-g 组 用户
useradd -g deploy deploy
新建用户nginx,位于www组,且不可登录,用于启动nginx:
useradd -s /sbin/nologin -g www nginx
为用户deploy设置密码:
# passwd deploy
Changing password for user deploy.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
新建用户test,位于www组,并为其设置密码为1234567890:
useradd -g www -p test
2. 修改用户——usermod gpasswd
# usermod
Usage: usermod [options] LOGIN Options:
-a, --append append the user to the supplemental GROUPS
(use only with -G)
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the new
location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-Z, --selinux-user new selinux user mapping for the user account
将用户test登录目录设为/home/test,并将其添加到www组:
usermod -d /home/test -G www test
将用户test追加到deploy组:
usermod -a -G deploy test
注意:如果没有-a,将直接变更用户所在组,即将用户从原所在组中移除!
这时候用gpasswd就比较安全一些!
gpasswd -a test deploy
将用户test从www组中移除:
gpasswd -d test www
3. 删除用户——userdel
删除用户test,并移除其登录目录:
userdel -r test
Linux 命令整理 —— 用户管理的更多相关文章
- Linux命令整理,用户管理,用户组管理,系统管理,目录管理常用命令
知识点梳理 Linux课堂笔记 学习目标 能够知道什么是Linux系统以及它的应用场景 能够独立完成安装VMware虚拟机和网络配置 能够独立完成安装CentOS以及远程终端SecureCRT 能够熟 ...
- Linux命令(用户管理、组和时间管理)
用户管理 Linux系统是一个多用用户的系统 用户分为三类: 超级用户(root)用户的id是0 伪用户 用户的id是1----499,虽然存在,但不能被登录 ...
- linux命令之用户管理及用户信息查询命令(下)
1.visudo:编辑sudoers文件 该命令专门用来编辑/etc/sudoers文件,同时提供语法检查等功能. 示例: 1)执行visudo对普通用户授权 [root@boxiaoyuan ~]# ...
- linux命令之用户管理及用户信息查询命令(上)
1.useradd:创建用户 该命令用于创建新的用户或者更改用户的信息. 参数 说明 -g 指定用户对应的用户组,用户组 -s 用户登录后使用的Shell名称 -u 用户的ID值 示例: 1)user ...
- Linux系列教程(七)——Linux帮助和用户管理命令
上篇博客我们介绍了Linux文件搜索命令,其中find是用的最多的也是功能最强大的文件或目录搜索命令,和另一个搜索命令locate的区别是,find命令是全盘搜索,刚创建的文件也能搜索的到,而loca ...
- Linux学习之用户管理命令与用户组管理命令(十五)
Linux学习之用户管理命令与用户组管理命令 目录 用户管理命令 用户添加命令useradd 修改用户密码passwd 修改用户信息usermod 修改用户密码状态chage 删除用户userdel ...
- 安装VMtools vim编辑器的使用 压缩包命令 Linux下的用户管理 (第三天)
VM tools:方便我们虚拟机和宿主机之间复制数据或移动文件等 安装VMtools 1.菜单栏-虚拟机-安装VM tools 将其选中 2.进入系统,在桌面位置里面有VM tools的光盘,双击进入 ...
- linux上的用户管理
作为一个专业的服务器发行版,CentOS上存在着n多个用户,作为一个专业的运维工程师,linux的用户管理和用户组的管理是做为一个SA必不可少的工作. 下面我们就先来谈谈linux中的用户管理: us ...
- Linux常用命令5 用户管理命令
1.用户管理命令:useradd 所在路径:/usr/bin/useradd 执行权限:root 语法:useradd 用户名 功能描述:添加新用户 例如:useradd hzw userd ...
随机推荐
- 未能找到任何适合于指定的区域性或非特定区域性的资源。请确保在编译时已将“xxx.Resources.resources”正确嵌入或链接到程序集
今天在测试一个工程的时候,突然遇到了这样一个问题: 错误信息:System.Resources.MissingManifestResourceException: 未能找到任何适合于指定的区域或非特定 ...
- 转载:简单介绍Python中的try和finally和with方法
用 Python 做一件很平常的事情: 打开文件, 逐行读入, 最后关掉文件; 进一步的需求是, 这也许是程序中一个可选的功能, 如果有任何问题, 比如文件无法打开, 或是读取出错, 那么在函数内需要 ...
- jQuery 简单漂亮的 Nav 导航菜单
自己写的一个简单的导航菜单,先看效果: 鼠标悬浮时菜单项向上移动成蓝底白字,点击之后底部会有蓝条表示当前选中项. 页面代码,菜单的每一项都是一个 div ,其中包括一个 ul 用来放置显示文字等,另一 ...
- AndroidStudio支持新的NDK的操作使用
在2015的Google I / O大会,5月底,谷歌宣布了一项新的支持由Android NDK Studio 1.3,Jetbrains CLion集成功能,Android gradle插件.这种支 ...
- eclipse 最全快捷键(网络收集)
Ctrl+1 快速修复(最经典的快捷键,就不用多说了) Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加) Ctrl+Alt+↑ 复制当前行到上一行(复制增加) Alt+ ...
- OpenSSL 安全漏洞: heartbleed
Heartbleed 是 2014年4月7日被广泛报道的一个 OpenSSL 安全漏洞,号称是灾难. 利用它能读取服务器上最多64k的内存,只要该服务器可以通过ssl连接. Heartbleed ...
- rinetd 安装使用
1 下载解压: wget http://www.boutell.com/rinetd/http/rinetd.tar.gz tar zxvf rinetd.tar.gz 2 手动建立目录 mkdir ...
- windows不能在本地计算机启动apache
今天,配置eclipse PHP studio 3.0的时候更改了apache http server 中的httpd.conf文件: 将DocumentRoot 的路径设错了,为一个不存在目录 .更 ...
- Highcharts条形与柱形同时显示
var chart; $(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'chart_combo' //关联页面元素di ...
- VS编译时自动下载NuGet管理的库
之前一直使用NuGet来管理一些第三方的库,但是每次check in代码时候为了保证编译通过,都需要把对应的packages check in. 比较耗费时间,特别是往github上同步代码,而且这些 ...