Merge pull request #9406 from geekpi/master

translated
This commit is contained in:
geekpi 2018-07-09 09:00:13 +08:00 committed by GitHub
commit 043a7f2da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 84 deletions

View File

@ -1,84 +0,0 @@
translating---geekpi
Migrating to Linux: Using Sudo
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ray-hennessy-233438-unsplash.jpg?itok=d4l7QUtF)
This article is the fifth in our series about migrating to Linux. If you missed earlier ones, you can catch up here:
[Part 1 - An Introduction][1]
[Part 2 - Disks, Files, and Filesystems][2]
[Part 3 - Graphical Environments][3]
[Part 4 - The Command Line][4]
You may have been wondering about Linux for a while. Perhaps it's used in your workplace and you'd be more efficient at your job if you used it on a daily basis. Or, perhaps you'd like to install Linux on some computer equipment you have at home. Whatever the reason, this series of articles is here to make the transition easier.
Linux, like many other operating systems supports multiple users. It even supports multiple users being logged in simultaneously.
User accounts are typically assigned a home directory where files can be stored. Usually this home directory is in:
```
/home/<login name>
```
This way, each user has their own separate location for their documents and other files.
### Admin Tasks
In a traditional Linux installation, regular user accounts don't have permissions to perform administrative tasks on the system. And instead of assigning rights to each user to perform various tasks, a typical Linux installation will require a user to log in as the admin to do certain tasks.
The administrator account on Linux is called root.
### Sudo Explained
Historically, to perform admin tasks, one would have to login as root, perform the task, and then log back out. This process was a bit tedious, so many folks logged in as root and worked all day long as the admin. This practice could lead to disastrous results, for example, accidentally deleting all the files in the system. The root user, of course, can do anything, so there are no protections to prevent someone from accidentally performing far-reaching actions.
The sudo facility was created to make it easier to login as your regular user account and occasionally perform admin tasks as root without having to login, do the task, and log back out. Specifically, sudo allows you to run a command as a different user. If you don't specify a specific user, it assumes you mean root.
Sudo can have complex settings to allow users certain permissions to use sudo for some commands but not for others. Typically, a desktop installation will make it so the first account created has full permissions in sudo, so you as the primary user can fully administer your Linux installation.
### Using Sudo
Some Linux installations set up sudo so that you still need to know the password for the root account to perform admin tasks. Others, set up sudo so that you type in your own password. There are different philosophies here.
When you try to perform an admin task in the graphical environment, it will usually open a dialog box asking for a password. Enter either your own password (e.g., on Ubuntu), or the root account's password (e.g., Red Hat).
When you try to perform an admin task in the command line, it will usually just give you a "permission denied" error. Then you would re-run the command with sudo in front. For example:
```
systemctl start vsftpd
Failed to start vsftpd.service: Access denied
sudo systemctl start vsftpd
[sudo] password for user1:
```
### When to Use Sudo
Running commands as root (under sudo or otherwise) is not always the best solution to get around permission errors. While will running as root will remove the "permission denied" errors, it's sometimes best to look for the root cause rather than just addressing the symptom. Sometimes files have the wrong owner and permissions.
Use sudo when you are trying to perform a task or run a program and the program requires root privileges to perform the operation. Don't use sudo if the file just happens to be owned by another user (including root). In this second case, it's better to set the permission on the file correctly.
Learn more about Linux through the free ["Introduction to Linux" ][5]course from The Linux Foundation and edX.
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/2018/3/migrating-linux-using-sudo
作者:[John Bonesio][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/johnbonesio
[1]:https://www.linux.com/blog/learn/intro-to-linux/2017/10/migrating-linux-introduction
[2]:https://www.linux.com/blog/learn/intro-to-linux/2017/11/migrating-linux-disks-files-and-filesystems
[3]:https://www.linux.com/blog/learn/2017/12/migrating-linux-graphical-environments
[4]:https://www.linux.com/blog/learn/2018/1/migrating-linux-command-line
[5]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -0,0 +1,82 @@
迁移到 Linux使用 Sudo
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ray-hennessy-233438-unsplash.jpg?itok=d4l7QUtF)
本文是我们关于迁移到 Linux 的系列文章的第五篇。如果你错过了之前的那些,你可以在这里赶上:
[第1部分 - 介绍][1]
[第2部分 - 磁盘,文件和文件系统][2]
[第3部分 - 图形环境][3]
[第4部分 - 命令行][4]
你可能一直想了解 Linux。也许它在你的工作场所使用如果你每天使用它你的工作效率会更高。或者也许你想在家里的某些计算机上安装 Linux。无论是什么原因这一系列文章都是为了让过渡更容易。
与许多其他操作系统一样Linux 支持多用户。它甚至支持多个用户同时登录。
用户帐户通常会被分配一个可以存储文件的家目录。通常这个家目​​录位于:
```
/home/<login name>
```
这样,每个用户都有存储自己的文档和其他文件的独立位置。
### 管理任务
在传统的 Linux 安装中,常规用户帐户无权在系统上执行管理任务。典型的 Linux 安装将要求用户以管理员身份登录以执行某些任务,而不是为每个用户分配权限以执行各种任务。
Linux 上的管理员帐户称为 root。
### Sudo 解释
从历史上看,要执行管理任务,必须以 root 身份登录,执行任务,然后登出。这个过程有点乏味,所以很多人以 root 登录并且整天都以管理员身份工作。这种做法可能会导致灾难性的后果例如意外删除系统中的所有文件。当然root 用户可以做任何事情,因此没有任何保护措施可以防止有人意外地执行影响很大的操作。
创建 sudo 工具是为了使你更容易以常规用户帐户登录,偶尔以 root 身份执行管理任务而无需登录、执行任务然后登出。具体来说sudo 允许你以不同的用户身份运行命令。如果你未指定特定用户,则假定你指的是 root 用户。
Sudo 可以有复杂的设置,允许用户使用有权限使用 sudo 运行某些命令,而其他的不行。通常,桌面安装会使创建的第一个帐户在 sudo 中有完全的权限,因此你作为主要用户可以完全管理 Linux 安装。
### 使用 Sudo
某些 Linux 安装设置了 sudo因此你仍需要知道 root 帐户的密码才能执行管理任务。其他人,设置 sudo 输入自己的密码。这里有不同的哲学。
当你尝试在图形环境中执行管理任务时,通常会打开一个要求输入密码的对话框。输入你自己的密码(例如,在 Ubuntu 上)或 root 帐户的密码例如Red Hat
当你尝试在命令行中执行管理任务时,它通常只会给你一个 “permission denied” 错误。然后你在前面用 sudo 重新运行命令。例如:
```
systemctl start vsftpd
Failed to start vsftpd.service: Access denied
sudo systemctl start vsftpd
[sudo] password for user1:
```
### 何时使用 Sudo
以 root 身份运行命令(在 sudo 或其他情况下)并不总是解决权限错误的最佳解决方案。虽然将以 root 身份运行将移除 “permission denied” 错误,但有时最好寻找根本原因而不是仅仅解决症状。有时文件拥有错误的所有者和权限。
当你在尝试一个需要 root 权限来执行操作的任务或者程序时使用 sudo。如果文件恰好由另一个用户包括 root 用户)拥有,请不要使用 sudo。在第二种情况下最好正确设置文件的权限。
通过 Linux 基金会和 edX 的免费[“Linux 介绍”][5]课程了解有关 Linux 的更多信息。
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/learn/2018/3/migrating-linux-using-sudo
作者:[John Bonesio][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linux.com/users/johnbonesio
[1]:https://www.linux.com/blog/learn/intro-to-linux/2017/10/migrating-linux-introduction
[2]:https://www.linux.com/blog/learn/intro-to-linux/2017/11/migrating-linux-disks-files-and-filesystems
[3]:https://www.linux.com/blog/learn/2017/12/migrating-linux-graphical-environments
[4]:https://www.linux.com/blog/learn/2018/1/migrating-linux-command-line
[5]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux