27 February 2019

recreating a user

a short while back, i made an attempt to switch my home shell from bash to xonsh. in the process of doing this, i took more of a raw approach. despite the learning process that was, it left me with scars.

these scars are specific to my system's user management and my account (see the last paragraph of the shell switch post). i no longer had a recognized user requiring me to type in my username rather than just typing in my password.

today, i made the attempt to fix that. now, i will admit there might be a better way out there to do this, but i took this (raw) route again.

with superuser privileges, i edited the /etc/passwd file and appened a digit to my username and changed my user id to 1001. i did this in the /etc/group and /etc/shadow files.

i then created a new user with my original name using this command (as root):

# useradd mock -d /home/mock -M -u 1000 -G wheel -U

i set the password for the replacement user, and i rebooted the system for all the things to be recognized. (i came back later to add the other groups to which this user belonged.)

the command created the new user with the established name assigning the original user id to the new user and the original user's home directory also to the new user. because the user id is the same, all filesystem permissions still belong to the appropriate user.

i then removed the old, modified username from the /etc/passwd and /etc/group files.

now, things are back to normal.

08 February 2019

when to use less instead of vim

i am baffled that so many people feel like vim is the correct tool for viewing files on linux systems. using vim to view files you'd edit is fine. when i am viewing code or a config file which i may change, i might use vim but only if i plan on making changes to the file.

but when i am going to view a file which i don't ever plan to edit or ever need to edit, i use less. log files are ones where i see this happening very often. unless you expect to change the log file, i see no reason for using vim.

even when viewing files which could be edited, it's best to use less. scenario: someone wants to view a file. they use vim. i jump on the server and need to actually change the file. i get the message that the file is already being edited. maybe i can say that i want to edit it anyway, but there are no guarantees someone won't :wq or ZZ out of the file and undo my changes. if they used less, there would be no threat of this.

less lets me move through a file much quicker for pure examination purposes. spacebar works like CTRL+F to scroll a page at time, yet all the vim moving commands are available too. searching text is the same as vim. and i can exit less with a simple tapping of the q key.

"but, but i need line numbers and vim lets me do that!" so does less. use the -N option on less to get line numbers.

"what if learn that i need to edit a file after i have entered less?" just press v in less to enter vim mode.

and a side annoyance are any leftover swap files vim might leave behind on a dirty exit of vim. swap files for log files? how first-year cadet is that?

if you feel the outstanding need to use vim to view files which should never be edited, then use the -R argument to ensure the file is never changed. if you practice using the -R, i am willing to bet you'd find typing less much easier.

and before you ask me, "why not use more?" i will let you figure out why less is more. (and if you are viewing files with nano, there are no words to describe that insanity.)

bonus assignment: find out what the view command does.