From 4ee289e41c0234e5c57a2b88533ea22def27f4f0 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 27 Jan 2023 10:32:05 -0600 Subject: [PATCH] Add Safely Edit The Sudoers File With Vim as a Unix TIL --- README.md | 3 ++- unix/safely-edit-the-sudoers-file-with-vim.md | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 unix/safely-edit-the-sudoers-file-with-vim.md diff --git a/README.md b/README.md index 207e1db..b493879 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/unix/safely-edit-the-sudoers-file-with-vim.md b/unix/safely-edit-the-sudoers-file-with-vim.md new file mode 100644 index 0000000..d9b0b34 --- /dev/null +++ b/unix/safely-edit-the-sudoers-file-with-vim.md @@ -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)