Overview
- Note the linux commands I need to use.
Users Management
ACTIVATE The Added Group Without Login
# When you added user to group via "usermod" command, it doesn't prompt immediately.
# You cna relogin the useranme or type "newgrp" command to enable it.
$ newgrp [-] [group]
ADD The User & Password
# -d: -d [home_dir], The new user will be created using HOME_DIR as the value for the user's login directory
# -G: -G GROUP1[,GROUP2,...[,GROUPN]]], A list of supplementary groups, separated by a comma, and no intervening whitespace
# -m: Create the user's home directory if it does not exist
# -p: -p [password], The password should be encrypted, the default is to disable the password
# -s, -s /bin/bash, The name of the user's login shell, set it as /bin/bash is recommended
$ sudo useradd -m -s /bin/bash -d [home_dir] -G [group] [username]
$ sudo passwd [username]
# SET user account and password in ONE line
$ useradd -p $(openssl passwd -1 password) -m -s /bin/bash -d [home_dir] -G [group] username
BATCH Comment & Uncomment
# Batch Comment
# Step1. Vim file
# Step2. Ctrl+v, enter "VISUAL BLOCK" mode
# Step3. Up & Down to scroll group
# Step4. Shift+i
# Step5. Type "#" in the first line
# Step6. Type Esc
# Step7. Type :wq Save & Quit
# Batch Uncomment
# Step1. Vim file
# Step2. Ctrl+v, enter "VISUAL BLOCK" mode
# Step3. Up & Down to scroll group
# Step4. Type d
# Step5. Type :wq Save & Quit
CHANGE The Mode Of Files And Directories
# It uses byte to identify the authority of each level, User, Group and Others
$ chmod [-cfvR] [--version] mode file...
e.g.
# Everyone can read, write and execute file
$ chmod 777 file
CHANGE The Owner Of The File
$ chown -R [username]:[groupname] [filename]
CHANGE The User’s HOME_DIR
# The usermod command supports "-d" flag to change the HOME_DIR path.
$ sudo usermod -d /new/home/path [username]
CHANGE The User’s Info
# The usermod command supports "-c" flag to change the user info.
$ sudo usermod -c [New User Info] [USERNAME]
CHANGE The User’s Name
# The usermod command supports "-l" flag to change the username.
$ sudo usermod -l [new_username] [old_username]
CHANGE The Group’s Name
# The groupmod command supports "-n" flag to change the group name.
$ sudo groupmod -n [NEW_GROUPNAME] [OLD_GROUPNAME]
CHANGE The Hostname / Computer Nmae
# The hostnamectl command supports "set-hostname" flag to change the hostname
# The commandline info doesn't changes util re-login, but it changes immediately on hostname and hostnamectl command
# The [new hostname] allows "-","a-z","0-9" only, "_"(underscore) is not-allowed
$ hostnamectl set-hostname [new hostname].
CHANGE / SETUP The User’s Home Directory
$ usermod -d [home directory] [username]
$ usermod -d /home/jenkins jenkins
# Verify $Home directory has changed
$ echo $HOME
DELETE The User’s Account
# [NOTICE] BECAREFUL! This command will DELETE USER
$ sudo deluser [username]
FIND The Process Name Via PID
$ sudo ps -fp [PID]
FIND The Current Location
- It shows the current directory path
$ pwd
/home/rpiauto
FIND The OS Info
- To identify which OS platform in your docker container
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.4 LTS"
or
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
INTRODUCE The Common Groups
# Introduce the common groups, so you will know which groups you need to add
# dialout, the dialout group controls ttyUSB devices, you need get the permission to logging console and access
LIST Users
$ cat /etc/passwd
LIST Groups And Belonged Users
$ cat /etc/group
LIST The Groups That The User Has Joined
$ groups [username]
[username] : [list of groups]
REMOVE The User From The Group
$ sudo deluser [username] [group]
SET Number In Vim Editor Permanently
# Show number list in Vim editor
# Create the .vimrc file if not exists
$ touch ~/.vimrc
# Edit the .vimrc file
$ vim ~/.vimrc
# Add your desired settings, such as enabling line numbers:
$ set number
# Save & Exit
# You will see the number list shows on the left in the opened file
Users Management
- How to Create Users in Linux (useradd Command)
- How to Remove or Delete a User in Linux
- useradd command in Linux with examples
- How To Change The HOME_DIR Of User
- How To Change The USERNAME In Linux
- How To Rename a Group in Linux
- Understanding /etc/passwd file fields
- Change User Info on the Command Line
- When trying to change username, terminal tells me user is currently used by process
- 5 Ways to Change Hostname on Linux - wikiHow
- How to Change Hostname on Ubuntu
- Linux “chmod” Commands