ls /home
root@arch-virtual-machine:/home# ls
arch cxxu roo
sudo adduser
➜ ~ sudo adduser cxxu_kali
Adding user `cxxu_kali' ...
Adding new group `cxxu_kali' (1000) ...
Adding new user `cxxu_kali' (1000) with group `cxxu_kali' ...
Creating home directory `/home/cxxu_kali' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for cxxu_kali
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
➜ ~ sudo adduser cxxu_kali sudo
Adding user `cxxu_kali' to group `sudo' ...
Adding user cxxu_kali to group sudo
Done.
中途不想填写的可以直接回车继续
adduser
来添加linux用户xxuser is not in the sudoers file. This incident will be reported.
sudo adduser sudo
赋予该用户sudo的使用权cxxu@iZ2zef3tpqffm5ydsjqi4zsdsZ:/etc/apt$ su -
Password:
root@iZ2zef3tpqffm5ydjdfsfqi4zsZ:~# sudo addusr cxxu sudo
sudo: addusr: command not found
root@iZ2zef3tpqffm5ydjqi4zsZ:~# sudo adduser cxxu sudo
Adding user `cxxu' to group `sudo' ...
Adding user cxxu to group sudo
Done.
ps -u
以下操作建议再sudo权限下执行
sudo pkill -KILL -u
pkill
command will find and kill processes. We’re passing in the KILL
signal, and using the -u
(user) option.sudo deluser --remove-home
┌──(cxxu_maintainer㉿CxxuWin11)-[/mnt/c/Users/cxxu]
└─$ sudo deluser --remove-home cxxu_kali
Looking for files to backup/remove ...
Removing user `cxxu_kali' ...
Warning: group `cxxu_kali' has no more members.
Done.
userdel
删除用户sudo userdel --remove
将一并删除用户家目录
deleteUser
deleteUser(){
sudo pkill -KILL -u $1
sudo deluser --remove-home $1
}
deleteLinuxUser(){
sudo pkill -KILL -u $1
sudo userdel --remove $1
}
su -l
切换到指定用户
-l
可以简写为 -
root
In Linux, the
su
command (switch user) is used to run a command as a different user.
The su
command is used to run a function as a different user. It is the easiest way to switch or change to the administrative account in the current logged in session.
Some versions of Linux, like Ubuntu, disable the root user account by default making the system more secure. But, this also restricts the user from running specific commands.
Using su
to temporarily act as a root user allows you to bypass this restriction and perform different tasks with different users.
Note : A root account is a master administrator account with full access and permissions in the system. Because of the severity of changes this account can make, and because of the risk of it being compromised, most Linux versions use limited user accounts for normal use.
To use the su
command, enter it into a command-line as follows:
su [options] [username [arguments]]
If a username is specified, su
defaults to the superuser (root). Simply find the user you need and add it to the su
command syntax.
To display a list of commands, enter the following:
su –h
cxxu@iZ2zef3tpqffm5ydjqi4zsZ:/etc/apt$ su -h
Usage: su [options] [LOGIN]
Options:
-c, --command COMMAND pass COMMAND to the invoked shell
-h, --help display this help message and exit
-, -l, --login make the shell a login shell
-m, -p,
--preserve-environment do not reset environment variables, and
keep the same shell
-s, --shell SHELL use SHELL instead of the default in passwd
To switch the logged-in user in this terminal window, enter the following:
su –l [other_user]
You’ll be asked for a password. Enter it, and the login will change to that user.
If you omit a username, it will default to the root account. Now, the logged-in user can run all system commands. This will also change the home directory and path to executable files.
Use the whoami
command to verify you switched to a different user.
Note : If you are having issues with authentication, you can change the root or sudo password in a couple of simple steps.
To run a specific command as a different user, use the –c
option:
su –c [command] [other_user]
The system will respond by asking you for the user password.
When you enter this example, the system will use the specified account to run the ls
(list directory contents) command.
To use a different shell, or operating environment, enter the following:
su –s /usr/bin/zsh
This command opens a root user account in Z shell .
You can keep the environment of the current user account with the –p
option:
su –p [other_user]
Replace [other_user] with the actual username you want to switch to.
The user account will switch, but you’ll keep the same home directory. This is useful if you need to run a command as a different user, but you need access to the current user’s data.
To verify you remained in the same home environment, use the echo $HOME
command that will display the directory you are working in.
sudo
command grants a one-time or limited-time access to root functionality.sudo
command is used to quickly run an administrative command, then return to the user account’s regular permissions.To provide sudo access, the user has to be added to the sudo group.
Note : By default, some versions of Linux (such as Ubuntu) disable the root account. That means there’s no password assigned to the root user. However you can switch to root by running the following command and entering the currently logged-in user’s password:
sudo su -
su
command lets you switch the current user to any other user.–l [username]
option to specify the user account.su
can also be used to change to a different shell interpreter on the fly.su
is an older but more fully-featured
command.
sudo
by use of the –c
option to pass a single command to the shell.reference link:Creating a new user and modifying its privileges in Linux
How to Delete a User on Linux (and Remove Every Trace) (howtogeek.com)
How to Delete a User on Linux (and Remove Every Trace)1. User Accounts on Linux
How To List Users and Groups on Linux – devconnected