添加用户

  1. $ useradd -m username

设定密码

  1. $ passwd username

删除用户

  1. $ userdel -r username

切换用户

  1. $ su username

查看当前用户所属的组

一个用户可以属于多个组

  1. $ groups

将用户加入到组

  1. $ usermod -G groupName username

查看系统所有用户组

系统所有用户及所有组信息分别记录在两个文件中: /etc/passwd, /etc/group
查看所有用户及权限: $ more /etc/passwd
查看所有用户组及权限: $ more /etc/group

更改读写权限

  1. $ chmod UserMark(+|-)PermissionsMark

UserMark 取值:

  • u: 用户
  • g: 组
  • o: 其他用户
  • a: 所有用户

PermissionsMark 取值:

  • r: 读
  • w: 写
  • x: 执行

例如:

  1. $ chmod a+x test.txt
  2. $ chmod g+w test2.txt

数字方式: 4(读), 2(写), 1(执行)

  1. % chmod 740 test.txt # 用户权限设置为 rwxr-----

更改文件或目录的拥有者

  1. $ chown username dirOrFile

使用 -R 递归更改目录下所有文件的拥有者:

  1. $ chown -R weber server/

环境变量

bashrc 与 profile 都用于保存用户的环境信息, bashrc 用于交互式 non-loginshell, profile 用户交互式 login shell.

/etc/profile. /etc/bashrc 是系统全局环境变量设定
~/.profile, ~/.bashrc 是用户目录下私有环境变量设定

~/.profile 登入时执行一次
~/.bashrc 每次 shell script 的执行都会使用它一次

  1. .bashrc
  2. alias m='more'
  3. alias cp='cp -i'
  4. alias mv='mv -i'
  5. alias ll='ls -l'
  6. alias lsl='ls -lrt'
  7. alias lm='ls -al|more'
  8. log=/opt/applog/common_dir
  9. unit=/opt/app/unittest/common
  10. .bash_profile
  11. . /opt/app/tuxapp/openav/config/setenv.prod.sh.linux
  12. export PS1='$PWD#'

通过上述设置,我们进入 log 目录就只需要输入 cd $log 即可