权限 chown chmod
- chown – change file owner and group
- chmod – change file modes or Access Control Lists
su 与 sudo
1.共同点:都是root用户的权限; 2.不同点:su仅仅取得root权限,工作环境不变,还是在切换之前用户的工作环境;sudo是完全取得root的权限和root的工作环境。
- sudo 命令需要输入当前用户的密码,su 命令需要输入 root 用户的密码。
- 另外一个区别是其默认行为。sudo 命令只允许使用提升的权限运行单个命令,而 su 命令会启动一个新的 shell,同时允许使用 root 权限运行尽可能多的命令,直到明确退出登录。
sudo -i root与sudo - root、sudo -i ,sudo - ,sudo root效果相同 提示输入密码时该密码为当前账户的密码 要求执行该命令的用户必须在sudoers中才可以 su需要的是切换后账户的密 用法为“su 账户名称”
sudo : 暂时切换到超级用户模式以执行超级用户权限,一般指的是root用户,提示输入密码时该密码为当前用户的密码,而不是超级账户的密码。不过有时间限制,Ubuntu默认为一次时长15分钟。
su : 切换到某某用户模式,提示输入密码时该密码为切换后账户的密码,用法为“su 账户名称”。如果后面不加账户时系统默认为root账户,密码也为超级账户的密码。没有时间限制。
sudo -i: 为了频繁的执行某些只有超级用户才能执行的权限,而不用每次输入密码,可以使用该命令。提示输入密码时该密码为当前账户的密码。没有时间限制。执行该命令后提示符变为“#”而不是“$”。想退回普通账户时可以执行“exit”或“logout” 。要求执行该命令的用户必须在sudoers中才可以
sudo su 运行sudo命令给su命令提权,运行su命令。要求执行该命令的用户必须在sudoers中才可以。
sudo su -
切换环境变量
|
|
su - root 和 su root(su)区别
su - root:表示人以root身份登录,创建一个新的环境(由 root 用户 ~/.bashrc
文件所设置的环境),相当于使用 root 用户正常登录(从登录屏幕登录)。
su root:表示与root建立一个链接,通过root执行命令,切换到 root 用户之后仍然保持旧的(或者说原始用户的)环境。
最直接的区别就是su目录还是原先用户的目录
但是 su - root
后目录就变为root用户的主目录了。
用户与组
wheel 的特殊管理组
在 一般情况下,一般用户通过执行“su -”命令、输入正确的root密码,可以登录为root用户来对系统进行管理员级别的配置。但是,为了更进一步加强系统的安全性,有必要建立一个管理员的 组,只允许这个组的用户来执行“su -”命令登录为root用户,而让其他组的用户即使执行“su -”、输入了正确的root密码,也无法登录为root用户。在UNIX下,这个组的名称通常为“wheel”。
|
|
用户列表文件:/etc/passwd
用户组列表文件:/etc/group
|
|
|
|
wheel 组的用户可以不用密码 sudo 到 root
ynthm ALL=(ALL) ALL
%wheel ALL=(ALL) NOPASSWD: ALL
chown – change file owner and group
用来更改某个目录或文件所属的用户名和用户组
|
|
|
|
chmod – change file modes or Access Control Lists
|
|
修改某个目录或文件的访问权限。
modes
- 4000 (the setuid bit). Executable files with this bit set will run with effective uid set to the uid of the file owner. Directories with this bit set will force all files and sub-directories created in them to be owned by the directory owner and not by the uid of the creating process, if the underlying file system supports this feature: see chmod(2) and the suiddir option to mount(8).
- 2000 (the setgid bit). Executable files with this bit set will run with effective gid set to the gid of the file owner.
- 1000 (the sticky bit). See chmod(2) and sticky(7).
- 0400 Allow read by owner.
- 0200 Allow write by owner.
- 0100 For files, allow execution by owner. For directories, allow the owner to search in the directory.
- 0040 Allow read by group members.
- 0020 Allow write by group members.
- 0010 For files, allow execution by group members. For directories, allow group members to search in the directory.
- 0004 Allow read by others.
- 0002 Allow write by others.
- 0001 For files, allow execution by others. For directories allow others to search in the directory.
说明
|
|
- 4 代表读
- 2 代表写
- 1 代表 文件执行/文件夹查询
- 7=4+2+1 代表所有三种权限
- 6=4+2 代表可读可写
- 5=4+1 代表可读以及文件执行/文件夹查询
The symbolic mode is described by the following grammar:
- mode ::= clause [, clause …]
- clause ::= [who …] [action …] action
- action ::= op [perm …]
- who ::= a | u | g | o
- op ::= + | - | =
- perm ::= r | s | t | w | x | X | u | g | o
操作对象who可是下述字母中的任一个或者它们的组合:
- a 表示“所有(all)用户”。它是系统默认值。
- u 表示“用户(user)”,即文件或目录的所有者。
- g 表示“同组(group)用户”,即与文件属主有相同组ID的所有用户。
- o 表示“其他(others)用户”。
操作符号可以是:
+
添加某个权限。-
取消某个权限。=
赋予给定权限并取消其他所有权限(如果有的话)。
设置 mode 所表示的权限可用下述字母的任意组合:
- r 可读。
- w 可写。
- x 可执行。
- X 只有目标文件对某些用户是可执行的或该目标文件是目录时才追加x 属性。
- s 在文件执行时把进程的属主或组ID置为该文件的文件属主。
- 方式“u+s”设置文件的用户ID位,“g+s”设置组ID位。
- t 保存程序的文本到交换设备上。
- u 与文件属主拥有一样的权限。
- g 与和文件属主同组的用户拥有一样的权限。
- o 与其他用户拥有一样的权限。
例子
- 644 make a file readable by anyone and writable by the owner only.
- go-w deny write permission to group and others.
- =rw,+X set the read and write permissions to the usual defaults, but retain any execute permissions that are currently set.
- +X make a directory or file searchable/executable by everyone if it is already searchable/executable by anyone.
- 755
- u=rwx,go=rx
- u=rwx,go=u-w make a file readable/executable by everyone and writable by the owner only.
- go= clear all mode bits for group and others.
- g=u-w set the group bits equal to the user bits, but clear the group write bit.