linux学习命令总结⑦

#useradd命令:建立用户帐号和创建用户的起始目录,使用权限是超级用户

[[email protected]_168_102_centos ~]# useradd test
[[email protected]_168_102_centos ~]# id test
uid=502(test) gid=502(test) groups=502(test)
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
test:x:502:502::/home/test:/bin/bash

useradd –u UID:创建用户时直接指定UID

[[email protected]_168_102_centos ~]# useradd -u 888 test_1
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
test_1:x:888:888::/home/test_1:/bin/bash

useradd –g GID:创建用户时直接指定GID,GID要事先存在

[[email protected]_168_102_centos ~]# useradd -g 500 test_2
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
test_2:x:889:500::/home/test_2:/bin/bash
[[email protected]_168_102_centos ~]# id test_2
uid=889(test_2) gid=500(wanghan) groups=500(wanghan)
[[email protected]_168_102_centos ~]# useradd -g 777 test_3
useradd: group ‘777‘ does not exist

useradd –G GID:创建用户时直接指定额外组,但组要事先存在

[[email protected]_168_102_centos ~]# useradd -G 500 test_3
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
test_3:x:890:890::/home/test_3:/bin/bash
[[email protected]_168_102_centos ~]# id test_3
uid=890(test_3) gid=890(test_3) groups=890(test_3),500(wanghan)

useradd –d:创建用户时指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录

[[email protected]_168_102_centos ~]# useradd -d /home/qidian -m test_6
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
test_6:x:893:893::/home/qidian:/bin/bash
[[email protected]_168_102_centos ~]# ls /home
abc  ceshi  openstack  qidian  test  test_1  test_2  test_3  wanghan

说明: –m:创建用户时,强制给用户创建主目录

useradd –M:创建用户,但不创建家目录

[[email protected]_168_102_centos ~]# ls /home
abc  ceshi  openstack  qidian  test  test_1  test_2  test_3  wanghan
[[email protected]_168_102_centos ~]# useradd -M test_7
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
test_7:x:895:895::/home/test_7:/bin/bash
[[email protected]_168_102_centos ~]# ls /home
abc  ceshi  openstack  qidian  test  test_1  test_2  test_3  wanghan

useradd -c:创建用户指定一段注释性描述,在/etv/passwd中查看

[[email protected]_168_102_centos ~]# useradd -c wanghan test_9
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
test_9:x:897:897:wanghan:/home/test_9:/bin/bash

useradd –s:创建用户时指定默认shell,应该指定/etc/shells文件出现的shell

[[email protected]_168_102_centos ~]# useradd -s tcsh test_10
useradd: invalid shell ‘tcsh‘
[[email protected]_168_102_centos ~]# useradd -s /bin/tcsh test_10
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
test_10:x:898:898::/home/test_10:/bin/tcsh

#groupadd命令:创建一个新组

[[email protected]_168_102_centos ~]# groupadd hp
[[email protected]_168_102_centos ~]# tail -n 1 /etc/group
hp:x:2001:

groupadd –g GID:创建新组并指定GID

[[email protected]_168_102_centos ~]# groupadd -g 2000 wudi
[[email protected]_168_102_centos ~]# tail -n 1 /etc/group
wudi:x:2000:
[[email protected]_168_102_centos ~]#

#userdel命令:删除用户,默认保留家目录

[[email protected]_168_102_centos ~]# userdel test_9
[[email protected]_168_102_centos ~]# tail /etc/passwd
test_1:x:888:888::/home/test_1:/bin/bash
test_2:x:889:500::/home/test_2:/bin/bash
test_3:x:890:890::/home/test_3:/bin/bash
test_4:x:891:891::/home/abc:/bin/bash
openstack:x:892:892::/home/openstack:/bin/bash
test_6:x:893:893::/home/qidian:/bin/bash
wanghan11:x:894:894::/tmp/wanghan:/bin/bash
test_7:x:895:895::/home/test_7:/bin/bash
test_8:x:896:896::/home/test_8:/bin/bash
test_10:x:898:898::/home/test_10:/bin/tcsh
[[email protected]_168_102_centos ~]# ls /home
abc  ceshi  openstack  qidian  test  test_1  test_10  test_2  test_3  test_8  test_9  wanghan

userdel -r:删除用户同时删除其家目录

[[email protected]_168_102_centos ~]# userdel -r test_8
[[email protected]_168_102_centos ~]# tail /etc/passwd
test:x:502:502::/home/test:/bin/bash
test_1:x:888:888::/home/test_1:/bin/bash
test_2:x:889:500::/home/test_2:/bin/bash
test_3:x:890:890::/home/test_3:/bin/bash
test_4:x:891:891::/home/abc:/bin/bash
openstack:x:892:892::/home/openstack:/bin/bash
test_6:x:893:893::/home/qidian:/bin/bash
wanghan11:x:894:894::/tmp/wanghan:/bin/bash
test_7:x:895:895::/home/test_7:/bin/bash
test_10:x:898:898::/home/test_10:/bin/tcsh
[[email protected]_168_102_centos ~]# ls /home
abc  ceshi  openstack  qidian  test  test_1  test_10  test_2  test_3  test_9  wanghan

#passwd命令:设定用户密码

管理员修改自身密码:

[[email protected]_168_102_centos ~]# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

管理员修改其他用户密码:

[[email protected]_168_102_centos ~]# passwd wanghan
Changing password for user wanghan.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

用户修改自身密码:

[[email protected]_168_102_centos rott]$ passwd
Changing password for user wanghan.
Changing password for wanghan.
(current) UNIX password:    //输入当前密码
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

passwd –l:锁定用户密码,用户不能修改密码

[[email protected]_168_102_centos ~]# passwd -l wanghan
Locking password for user wanghan.
passwd: Success
[[email protected]_168_102_centos ~]# su wanghan
[[email protected]_168_102_centos rott]$ passwd
Changing password for user wanghan.
Changing password for wanghan.
(current) UNIX password:
passwd: Authentication token manipulation error

passwd –u:解除用户密码锁定

[[email protected]_168_102_centos ~]# passwd -u wanghan
Unlocking password for user wanghan.
passwd: Success
[[email protected]_168_102_centos ~]# su wanghan
[[email protected]_168_102_centos rott]$ passwd
Changing password for user wanghan.
Changing password for wanghan.
(current) UNIX password:
New password:

passwd –S:显示用户密码简要信息

[[email protected]_168_102_centos ~]# passwd -S wanghan
wanghan PS 2014-08-12 0 99999 7 -1 (Password set, SHA512 crypt.)

#usermod命令:用来修改用户帐号的各项设定

usermod –u UID:修改用户UID

[[email protected]_168_102_centos ~]# id openstack
uid=892(openstack) gid=892(openstack) groups=892(openstack)
[[email protected]_168_102_centos ~]# usermod -u 588 openstack
[[email protected]_168_102_centos ~]# id openstack
uid=588(openstack) gid=892(openstack) groups=892(openstack)

usermod –g GID:修改用户GID

[[email protected]_168_102_centos ~]# id wanghan
uid=500(wanghan) gid=2000(wudi) groups=2000(wudi)
[[email protected]_168_102_centos ~]# usermod -g 2001 wanghan
[[email protected]_168_102_centos ~]# id wanghan
uid=500(wanghan) gid=2001(hp) groups=2001(hp)

usermod –G GID:修改用户附加组,默认覆盖原有附加组,同时使用-a选项则是再额外添加

[[email protected]_168_102_centos ~]# id user1
uid=899(user1) gid=899(user1) groups=899(user1),2000(wudi)
[[email protected]_168_102_centos ~]# usermod -G 2001 user1
[[email protected]_168_102_centos ~]# id user1
uid=899(user1) gid=899(user1) groups=899(user1),2001(hp)
[[email protected]_168_102_centos ~]# usermod -a -G 2000 user1
[[email protected]_168_102_centos ~]# id user1
uid=899(user1) gid=899(user1) groups=899(user1),2000(wudi),2001(hp)

usermod –c:修改用户帐号备注信息

[[email protected]_168_102_centos ~]# useradd -c hello user2
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
user2:x:900:900:hello:/home/user2:/bin/bash
[[email protected]_168_102_centos ~]# usermod -c test user2
[[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd
user2:x:900:900:test:/home/user2:/bin/bash

usermod -d:修改用户家目录,默认不会迁移家目录,同时使用-m则可迁移

[[email protected]_168_102_centos ~]# usermod -d /tmp/wanghan user1
[[email protected]_168_102_centos ~]# tail /etc/passwd
test_2:x:889:500::/home/test_2:/bin/bash
test_3:x:890:890::/home/test_3:/bin/bash
test_4:x:891:891::/home/abc:/bin/bash
openstack:x:588:892::/home/openstack:/bin/bash
test_6:x:893:893::/home/qidian:/bin/bash
wanghan11:x:894:894::/tmp/wanghan:/bin/bash
test_7:x:895:895::/home/test_7:/bin/bash
test_10:x:898:898::/home/test_10:/bin/tcsh
user1:x:899:899::/tmp/wanghan:/bin/bash
user2:x:900:900:test:/home/user2:/bin/bash
[[email protected]_168_102_centos ~]# usermod -d /tmp/user2/ -m user2
[[email protected]_168_102_centos ~]# tail /etc/passwd
test_2:x:889:500::/home/test_2:/bin/bash
test_3:x:890:890::/home/test_3:/bin/bash
test_4:x:891:891::/home/abc:/bin/bash
openstack:x:588:892::/home/openstack:/bin/bash
test_6:x:893:893::/home/qidian:/bin/bash
wanghan11:x:894:894::/tmp/wanghan:/bin/bash
test_7:x:895:895::/home/test_7:/bin/bash
test_10:x:898:898::/home/test_10:/bin/tcsh
user1:x:899:899::/tmp/wanghan:/bin/bash
user2:x:900:900:test:/tmp/user2/:/bin/bash

usermod –s:修改用户shell

 

linux学习命令总结⑦

时间: 2024-08-19 04:44:01

linux学习命令总结⑦的相关文章

linux学习命令总结②

#shutdown命令:系统关机.重启等 shutdown [options]- Time Time : now(马上) +#(多少分钟后) hh:mm(几点几分) 系统五分钟后关机: [[email protected]_168_102_centos ~]# shutdown 5//系统5分钟后重启 Broadcast message from [email protected]_168_102_centos (/dev/pts/0) at 16:19 ... The system is go

linux学习命令总结⑧

#chown命令:通过chown改变文件的属主和属组.在更改文件的属主或所属组时,可以使用用户名称和用户识别码设置.普通用户不能将自己的文件改变成其他的属主.其操作权限一般为管理员. 修改文件属主和属组: [[email protected]_168_102_centos ~]# ls -l total 8 drwxr-xr-x 2 wanghan hx 4096 Aug 12 10:32 abe drwxr-xr-x 2 root wanghan 4096 Aug 12 10:32 xab [

linux学习命令总结⑨

#重定向 输出重定向: 1>覆盖输出(1可省略) [[email protected]_168_102_centos tmp]# ls functions >shuchu [[email protected]_168_102_centos tmp]# cat shuchu functions [[email protected]_168_102_centos tmp]# ls fstab >shuchu [[email protected]_168_102_centos tmp]# ca

linux学习命令总结⑤

#stat命令:查看文件信息 [[email protected]_168_102_centos ~]# stat test.log File: `test.log' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 483339 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 500/ wanghan) Access:

linux学习命令总结③

#cd ~ 回到当前用户的家目录 [[email protected]_168_102_centos etc]# pwd /etc //当前所在目录 [[email protected]_168_102_centos etc]# cd ~ //回到当前用户家木里 [[email protected]_168_102_centos ~]# pwd /root //当前用户家目录 [[email protected]_168_102_centos ~]# su wanghan [[email pro

linux学习命令总结④

#ls命令:通过ls 命令不仅可以查看linux文件夹包含的文件,而且可以查看文件权限(包括目录.文件夹.文件权限),查看目录信息等等 [[email protected]_168_102_centos /]# ls bin data etc lib lost+found mnt proc sbin srv tmp var boot dev home lib64 media opt root selinux sys usr ls –a:显示所有文件,包含.开头的隐藏文件 [[email prot

linux学习命令总结⑩②

#fdisk命令:磁盘分区工具 fdisk –l:查看机器所挂硬盘个数及分区情况 [[email protected]_168_102_centos ~]# fdisk -l Disk /dev/xvda: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physic

linux学习命令总结⑥

#文件名通配 通配符: *:匹配任意长度的任意字符(0到多个) [[email protected]_168_102_centos ~]# ls * 0812080808 2014-05-16: test.log ceshi_1: test: [[email protected]_168_102_centos ~]# ls -ld t* drwxr-xr-x 2 root wanghan 4096 Aug 11 15:46 test ?:匹配任意单个字符 [[email protected]_1

Linux 学习命令之修改日期时间

Linux 学习命令之修改日期时间 一.日期时间修改 1. 查看时间和日期 [[email protected] ~]# date 2017年 11月 03日 星期五 11:39:49 CST 或 [[email protected] ~]# clock 2017年11月03日 星期五 11时42分52秒  -1.563496 seconds 显示日历 [[email protected] ~]# cal 十一月 2017 日 一 二 三 四 五 六 1  2  3  4 5  6  7  8