该篇博客,我将为大家介绍几个命令,其中有部分用法很难查到,希望对大家有帮助

1.chattr:

chattr命令用来改变文件属性。这项指令可改变存放在ext2文件系统上的文件或目录属性。

       chattr +A 文件    锁定某个文件的访问时间

       chattr -A 文件    解锁某个文件的访问时间

       chattr +i 文件    锁定文件,不能删除、改名、更改

       chattr +a 文件    只能对文件内容追加,不能修改


man帮助中的一些用法:

  a:让文件或目录仅供附加用途。 
 b:不更新文件或目录的最后存取时间。 
 c:将文件或目录压缩后存放。 
 d:将文件或目录排除在倾倒操作之外。 
 i:不得任意更动文件或目录。 
 s:保密性删除文件或目录。 
 S:即时更新文件或目录。 
 u:预防以外删除。 
 
参  数:
 -R  递归处理,将指定目录下的所有文件及子目录一并处理。 
 -v<版本编号>  设置文件或目录版本。 
 -V  显示指令执行过程。 
 +<属性>  开启文件或目录的该项属性。 
 -<属性>  关闭文件或目录的该项属性。 
 =<属性>  指定文件或目录的该项属性。


2.lsattr

lsattr: 显示文件属性(用chattr执行改变文件或目录的属性,可执行lsattr指令来查询其属性。)

         -a  显示所有文件和目录,包括以"."为名称开头字符的额外内建,现行目录"."与上层目录".."。 
  -d  显示,目录名称,而非其内容。 
  -l  此参数目前没有任何作用。 
  -R  递归处理,将指定目录下的所有文件及子目录一并处理。 
  -v  显示文件或目录版本。 
  -V  显示版本信息。



3.groupmems:用户主组的管理员成员


         -a  用户名    将一个用户添加到组成员列表

         -d  用户名    从组成员列表中删除用户

         -g  组  名    超级用户可以指定修改哪个组的组成员列表

         -l -g  组名   列出组成员

         -p -g  组名   从组成员列表中删除所有用户

配置文件

    /etc/login.defs 中有如下配置变量,可以用来更改此工具的行为:

#Please note that the parameters in this configuration file control the

# behavior of the tools from the shadow-utils component. None of these

# tools uses the PAM mechanism, and the utilities that use PAM (such as the

# passwd command) should therefore be configured elsewhere. Refer to

# /etc/pam.d/system-auth for more information.

#


# *REQUIRED*

#   Directory where mailboxes reside, _or_ name of file, relative to the

#   home directory.  If you _do_ define both, MAIL_DIR takes precedence.

#   QMAIL_DIR is for Qmail

#

#QMAIL_DIR      Maildir

MAIL_DIR        /var/spool/mail

#MAIL_FILE      .mail


# Password aging controls:

#

#       PASS_MAX_DAYS   Maximum number of days a password may be used.

#       PASS_MIN_DAYS   Minimum number of days allowed between password changes.

#       PASS_MIN_LEN    Minimum acceptable password length.

#       PASS_WARN_AGE   Number of days warning given before a password expires.

#

PASS_MAX_DAYS   99999

PASS_MIN_DAYS   0

PASS_MIN_LEN    5

PASS_WARN_AGE   7


#

# Min/max values for automatic uid selection in useradd

#

UID_MIN                   500

UID_MAX                 60000


#

# Min/max values for automatic gid selection in groupadd

#

GID_MIN                   500

GID_MAX                 60000


#

# If defined, this command is run when removing a user.

# It should remove any at/cron/print jobs etc. owned by

# the user to be removed (passed as the first argument).

#

#USERDEL_CMD    /usr/sbin/userdel_local


#

# Please note that the parameters in this configuration file control the

# behavior of the tools from the shadow-utils component. None of these

# tools uses the PAM mechanism, and the utilities that use PAM (such as the

# passwd command) should therefore be configured elsewhere. Refer to

# /etc/pam.d/system-auth for more information.

#


# *REQUIRED*

#   Directory where mailboxes reside, _or_ name of file, relative to the

#   home directory.  If you _do_ define both, MAIL_DIR takes precedence.

#   QMAIL_DIR is for Qmail

#

#QMAIL_DIR      Maildir

MAIL_DIR        /var/spool/mail

#MAIL_FILE      .mail


# Password aging controls:

#

#       PASS_MAX_DAYS   Maximum number of days a password may be used.

#       PASS_MIN_DAYS   Minimum number of days allowed between password changes.

#       PASS_MIN_LEN    Minimum acceptable password length.

#       PASS_WARN_AGE   Number of days warning given before a password expires.

#

PASS_MAX_DAYS   99999

PASS_MIN_DAYS   0

PASS_MIN_LEN    5

PASS_WARN_AGE   7


#

# Min/max values for automatic uid selection in useradd



4.chsh命令:

chsh命令用来更换登录系统时使用的shell。若不指定任何的参数和用户名称,则chsh会以应答的方式进行设置。


chsh(选项)(参数)

-s  shell名称              更改系统预设的shell环境

-l                         列出目前系统可用的shell清单

-u或--help                 在线帮助

-v                         显示版本信息


[root@localhost ~]# chsh -l

/bin/sh

/bin/bash

/sbin/nologin

/usr/bin/sh

/usr/bin/bash

/usr/sbin/nologin

/bin/tcsh

/bin/csh

   

[root@localhost ~]# chsh -s /bin/csh

Changing shell for root.

Shell changed.

[root@localhost ~]# getent passwd root            使用此命令修改过shell后,/etc/passwd中的 root:x:0:0:root:/root:/bin/csh                    root用户shell会被改为csh


5.pwconv           :同步用户信息,从/etc/passwd 到/etc/shadow

pwunconv         :pwcov 的逆向操作,从/etc/shadow创建/etc/passwd然后删除shadow文件;

grpconv          :通过/etc/group和/etc/gshadow 的文件内容来同步或创建/etc/gshadow ,如                        果/etc/gshadow 不存在则创建;

grpunconv        :通过/etc/group 和/etc/gshadow 文件内容来同步或创建/etc/group,然后删除                      gshadow文件。



6.newusers:批量创建用户   (需要先准备user.txt文件,格式按照/etc/passwd的格式写)

  newusers  user.txt        添加多个用户

  创建pass.txt文件,该文件格式:账号:密码

  cat pass.txt | chapasswd     将用户的密码写入/etc/shadow中

  此时/etc/passwd /etc/shadow /etc/group /etc/gshadow 中都有了这几个新用户信息,但用户此时   的家目录下的配置文件仍然为空,我们需要进行增加配置文件。

  cp -r /etc/skel   /home/用户名              skel目录为用户家目录的模板,进行复制

  chown -R 用户名:用户名   /home/用户名      对家目录的属主,属组进行修改