翻译完成

This commit is contained in:
MjSeven 2018-12-26 22:27:33 +08:00
parent 1c76716ea3
commit 99f483aaae
2 changed files with 105 additions and 111 deletions

View File

@ -1,111 +0,0 @@
Translating by MjSeven
Users, Groups and Other Linux Beasts: Part 2
======
![](https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2)
In this ongoing tour of Linux, weve looked at [how to manipulate folders/directories][1], and now were continuing our discussion of _permissions_ , _users_ and _groups_ , which are necessary to establish who can manipulate which files and directories. [Last time,][2] we showed how to create new users, and now were going to dive right back in:
You can create new groups and then add users to them at will with the `groupadd` command. For example, using:
```
sudo groupadd photos
```
will create the _photos_ group.
Youll need to [create a directory][1] hanging off the root directory:
```
sudo mkdir /photos
```
If you run `ls -l /`, one of the lines will be:
```
drwxr-xr-x 1 root root 0 jun 26 21:14 photos
```
The first _root_ in the output is the user owner and the second _root_ is the group owner.
To transfer the ownership of the _/photos_ directory to the _photos_ group, use
```
chgrp photos /photos
```
The `chgrp` command typically takes two parameters, the first parameter is the group that will take ownership of the file or directory and the second is the file or directory you want to give over to the the group.
Next, run `ls -l /` and you'll see the line has changed to:
```
drwxr-xr-x 1 root photos 0 jun 26 21:14 photos
```
You have successfully transferred the ownership of your new directory over to the _photos_ group.
Then, add your own user and the _guest_ user to the _photos_ group:
```
sudo usermod <your username here> -a -G photos
sudo usermod guest -a -G photos
```
You may have to log out and log back in to see the changes, but, when you do, running `groups` will show _photos_ as one of the groups you belong to.
A couple of things to point out about the `usermod` command shown above. First: Be careful not to use the `-g` option instead of `-G`. The `-g` option changes your primary group and could lock you out of your stuff if you use it by accident. `-G`, on the other hand, _adds_ you to the groups listed and doesn't mess with the primary group. If you want to add your user to more groups than one, list them one after another, separated by commas, no spaces, after `-G`:
```
sudo usermod <your username> -a -G photos,pizza,spaceforce
```
Second: Be careful not to forget the `-a` parameter. The `-a` parameter stands for _append_ and attaches the list of groups you pass to `-G` to the ones you already belong to. This means that, if you don't include `-a`, the list of groups you already belong to, will be overwritten, again locking you out from stuff you need.
Neither of these are catastrophic problems, but it will mean you will have to add your user back manually to all the groups you belonged to, which can be a pain, especially if you have lost access to the _sudo_ and _wheel_ group.
### Permits, Please!
There is still one more thing to do before you can copy images to the _/photos_ directory. Notice how, when you did `ls -l /` above, permissions for that folder came back as _drwxr-xr-x_.
If you read [the article I recommended at the beginning of this post][3], you'll know that the first _d_ indicates that the entry in the file system is a directory, and then you have three sets of three characters ( _rwx_ , _r-x_ , _r-x_ ) that indicate the permissions for the user owner ( _rwx_ ) of the directory, then the group owner ( _r-x_ ), and finally the rest of the users ( _r-x_ ). This means that the only person who has write permissions so far, that is, the only person who can copy or create files in the _/photos_ directory, is the _root_ user.
But [that article I mentioned also tells you how to change the permissions for a directory or file][3]:
```
sudo chmod g+w /photos
```
Running `ls -l /` after that will give you _/photos_ permissions as _drwxrwxr-x_ which is what you want: group members can now write into the directory.
Now you can try and copy an image or, indeed, any other file to the directory and it should go through without a problem:
```
cp image.jpg /photos
```
The _guest_ user will also be able to read and write from the directory. They will also be able to read and write to it, and even move or delete files created by other users within the shared directory.
### Conclusion
The permissions and privileges system in Linux has been honed over decades. inherited as it is from the old Unix systems of yore. As such, it works very well and is well thought out. Becoming familiar with it is essential for any Linux sysadmin. In fact, you can't do much admining at all unless you understand it. But, it's not that hard.
Next time, we'll be dive into files and see the different ways of creating, manipulating, and destroying them in creative ways. Always fun, that last one.
See you then!
Learn more about Linux through the free ["Introduction to Linux" ][4]course from The Linux Foundation and edX.
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2
作者:[Paul Brown][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linux.com/users/bro66
[1]:https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux
[2]:https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts
[3]:https://www.linux.com/learn/understanding-linux-file-permissions
[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -0,0 +1,105 @@
用户、组及其他 Linux 特性:第二部分
======
![](https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2)
在正在进行的 Linux 之旅中,我们了解了[如何操作文件夹或目录][1],现在我们继续讨论 _权限__用户_ 和 _组_,这对于确定谁可以操作哪些文件和目录是必要的。[上次][2],我们展示了如何创建新用户,现在我们将重新来一遍:
你可以使用 `groupadd` 命令创建新组,然后随意添加用户。例如,使用:
```
sudo groupadd photos
```
这将会创建 _photos_ 组。
你需要在根目录下[创建一个目录][1]
```
sudo mkdir /photos
```
如果你运行 `ls -l /`,结果中会有如下这一行:
```
drwxr-xr-x 1 root root 0 jun 26 21:14 photos
```
输出中的第一个 _root_ 是所属的用户,第二个 _root_ 是所属的组。
要将 _/photos_ 目录的所有权转移到 _photos_ 组,使用:
```
chgrp photos /photos
```
`chgrp` 命令通常采用两个参数,第一个参数是将要获得文件或目录所有权的组,第二个参数是希望交给组的文件或目录。
接着,运行 `ls -l /`,你会发现刚才那一行变了:
```
drwxr-xr-x 1 root photos 0 jun 26 21:14 photos
```
你已成功将新目录的所有权转移到了 _photos_ 组。
然后,将你自己的用户和 _guest_ 用户添加到 _photos_ 组:
```
sudo usermod <你的用户名> -a -G photos
sudo usermod guest -a -G photos
```
你可能必须注销并重新登录才能看到更改,但是当你这样做时,运行 `groups` 会将 _photos_ 显示为你所属的组之一。
(to 校正:这里的 primary group 翻译成什么更好点呢)
关于上面提到的 `usermod` 命令,需要指明几点。第一:注意要使用 `-G` 选项而不是 `-g` 选项。`-g` 选项更改你的主要组,如果你意外地使用它,它可能会锁定你的一些东西。另一方面,`-G` 将你 _添加(add)_ 到列出的组中,并没有干扰主要组。如果要将用户添加到多个组中,在 `-G` 之后逐个列出他们,用逗号分隔,不要有空格:
```
sudo usermod <your username> -a -G photos,pizza,spaceforce
```
第二点:小心点不要忘记 `-a` 参数。`-a` 参数代表 _追加(append)_,将你传递给 `-G` 的组列表附加到你已经属于的组。这意味着,如果你不包含 `-a`,那么你之前所属的组列表将被覆盖,再次将你从你需要的东西中锁定。(to 校正:最后这句话什么意思呢)
这些都不是灾难性问题,但这意味着你必须手动将用户添加回你所属的所有组,这可能是个麻烦,特别是如果你失去了对 _sudo__wheel_ 组的访问权限。
### 权限
在将图像复制到 _/photos_ 目录之前,还要做一件事情。注意,当你执行上面的 `ls -l /` 时,该文件夹的权限将以 _drwxr-xr-x_ 形式返回。
如果你阅读[我在本文开头推荐的文章][3],你将知道第一个 _d_ 表示文件系统中的条目是一个目录,接着你有三组三个字符 (_rwx_, _r-x_, _r-x_),它们表示目录的所属用户 (_rwx_) 的权限,然后是所属组 (_r-x_)的权限,最后是其他用户 (_r-x_) 的权限。这意味着到目前为止唯一具有写权限的人,即能够在 _/photos_ 目录中复制或创建文件的唯一人员是 _root_ 用户。
但是[我提到的那篇文章也告诉你如何更改目录或文件的权限][3]
```
sudo chmod g+w /photos
```
运行 `ls -l /`,你会看到 _/photos_ 权限变为了 _drwxrwxr-x_。这就是你希望的:组成员现在可以对目录进行写操作了。
现在你可以尝试将图像或任何其他文件复制到目录中,它应该没有问题:
```
cp image.jpg /photos
```
_guest_ 用户也可以从目录中读取和写入。他们也可以读取和写入,甚至移动或删除共享目录中其他用户创建的文件。(to 校正:这里 guest 可以从目录中读取和写入吗guest 不应该是 r-x 权限吗?)
### 总结
Linux 中的权限和特权系统已经磨练了几十年,它继承自昔日的旧 Unix 系统。就其本身而言,它工作的非常好,而且经过了深思熟虑。熟悉它对于任何 Linux 系统管理员都是必不可少的。事实上,除非你理解它,否则你根本就无法做很多事情。但是,这并不难。
下一次,我们将深入研究文件,并以一个创新的方式查看创建,操作和销毁文件的不同方法。最后一个总是很有趣。
回头见!
通过 Linux 基金会和 edX 的免费[" Linux 简介"][4]课程了解有关 Linux 的更多信息。
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2
作者:[Paul Brown][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[MjSeven](https://github.com/MjSeven)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linux.com/users/bro66
[1]:https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux
[2]:https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts
[3]:https://www.linux.com/learn/understanding-linux-file-permissions
[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux