mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add Safely Edit The Sudoers File With Vim as a Unix TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1278 TILs and counting..._
|
||||
_1279 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -1276,6 +1276,7 @@ _1278 TILs and counting..._
|
||||
- [Provide A Fallback Value For Unset Parameter](unix/provide-a-fallback-value-for-unset-parameter.md)
|
||||
- [Remove A Directory Called `-p`](unix/remove-a-directory-called-dash-p.md)
|
||||
- [Repeat Yourself](unix/repeat-yourself.md)
|
||||
- [Safely Edit The Sudoers File With Vim](unix/safely-edit-the-sudoers-file-with-vim.md)
|
||||
- [Saying Yes](unix/saying-yes.md)
|
||||
- [Search Files Specific To A Language](unix/search-files-specific-to-a-language.md)
|
||||
- [Search History](unix/search-history.md)
|
||||
|
||||
27
unix/safely-edit-the-sudoers-file-with-vim.md
Normal file
27
unix/safely-edit-the-sudoers-file-with-vim.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Safely Edit The Sudoers File With Vim
|
||||
|
||||
The sudoers file is a way on Unix systems to administer various levels of
|
||||
permissions to different users. It is important to make sure you "know what
|
||||
you're doing" when editing this file. Especially so because if you mangle the
|
||||
syntax of the file, you could lock out yourself and even the root user from
|
||||
doing all kinds of things. Even from being able to update and fix this file.
|
||||
|
||||
Fortunately, there is a command—`visudo`—that opens the sudoers file in an
|
||||
editor that will perform pre-save checks to ensure the file is valid syntax.
|
||||
|
||||
```bash
|
||||
$ visudo
|
||||
```
|
||||
|
||||
This command has `vi` in the name because it used to be that it would default
|
||||
to `vi` as the editor. On Ubuntu, at the very least, this has changed and the
|
||||
default is now `nano`.
|
||||
|
||||
If you'd like to still have `visudo` open to `vi` (or `vim`), you can specify
|
||||
that with the `SUDO_EDITOR` env var.
|
||||
|
||||
```bash
|
||||
$ SUDO_EDITOR=vim visudo
|
||||
```
|
||||
|
||||
[source](https://manpages.ubuntu.com/manpages/impish/en/man8/visudo.8.html#environment)
|
||||
Reference in New Issue
Block a user