当前位置:网站首页>9. User authority related commands
9. User authority related commands
2022-07-22 21:40:00 【WuJiaYFN】
One 、 user and jurisdiction Basic concepts of
1、 user
user Is in Linux An important part of the system work , User management Include user And Group Management of
stay Linux In the system , Whether by the local machine or the remote login system , Every system You have to have an account , And for the Different system resources have different permissions
stay Linux in , You can specify Every user in the light of Different files or directories Of Different authorities
Yes file / Catalog The authority of includes :
jurisdiction english narrow Number code read read r 4 Write write w 2 perform excute x 1 No authority - 0
2、 Group
- To facilitate user management , Put forward Group The concept of
- in application , In advance in the light of Group Set permissions , And then Different users are added to the group for , So you don't have to set permissions for each user in turn
3、ls -l Detailed description of display information
ls -l You can see Details of the files under the folder , From left to right :
- jurisdiction , If the first character is d Presentation directory , If it is - Said file
- Hard link number , Generally speaking , Is how many ways you can access At present Catalog / file
- The owner , Files in the home directory / Catalog The owner of is usually the current user
- Group , stay Linux Kind of , A lot of times When the group name and user name are the same
- size
- Creation or last modification time
- name
A detailed introduction to the number of hard links :
Be careful : The number of hard chain connections of files is generally 1, The more subdirectories of a directory , The more hard links it has
Two 、 User permissions —chmod Simple use of commands
chmod You can modify user / Group Yes file / Catalog Authority
The command format is :
chmod +/-rwx file name / Directory name
Be careful : If it is + , said Increase the permissions ; if - Number , It means to reduce permissions
rwx The three permissions can be combined at will
3、 ... and 、 The super user
- Linux In the system Of root account number Usually For system maintenance and management , All resources of the operating system With all access rights
- In most versions of Liunx in , None of them recommend Use it directly root Account login system
- stay Linux During installation , The system will automatically create a user account , The default user is called “ Standard users ”
sudo
- su yes substitute user Abbreviation , Express Use the identity of another user
- sudo A command is used to execute a command in another capacity , The preset identity is root
- The user to use sudo when , You must enter a password , After a 5 Minutes of validity , If the time limit is exceeded, you must re-enter the password
- If its unauthorized user attempts to use **sudo **, A warning email will be sent to the administrator
Ubuntu Into root Pattern :
Use sudo su command
, To exit root Mode can be used exit perhaps su user( User name when installing ) command
Four 、 Group management Terminal command
command | effect |
---|---|
groupadd Group name | add group |
groupdel Group name | Delete the group |
cat /etc/group | Determine group information |
chgrp -R Group name file / Directory name | Modify file / The group to which the catalog belongs |
Be careful :
- Create group / Delete the group All terminal commands need to be passed sudo Command execution ( Because standard users do not have this permission )
- Group information is saved in /etc/group In file
- /etc Directory is specially used to save System configuration information The catalog of
- in application , In advance in the light of Set permissions for the Group , Then add different users to the corresponding group , So you don't have to set permissions for each user in turn
# add to dev Group $ sudo groupadd dev # Check whether the group is added successfully $ cat /etc/group # take Python The group of the learning directory is changed to dev $ sudo chgrp -R dev Python Study / # Delete dev Group # sudo groupdel dev
5、 ... and 、 User management - Create delete user terminal command
command | effect | explain |
---|---|---|
useradd -m -g Group name New user name | Add new user | -m Automatically create user home directory -g Specify the group of users , Otherwise, a group with the same name as the user name will be created |
passwd user name | Set user password | If it's an ordinary user , Direct use passwd You can change your account password |
userdel -r user name | Delete user | -r Option will automatically delete the user's home directory |
cat/etc/passed | grep user name | Confirm user information | After creating a new user , User information will be saved in /etc/passwd In file |
Be careful :
Create user / Delete user / Change other user passwords All terminal commands need to use sudo perform
When you create a user , If you forget to add -m Option to specify the new user's home directory , The simplest solution is Delete user , Recreate
When you create a user , A and... Are created by default Group name with the same user name
User information is stored in /etc/passwd In file
6、 ... and 、 User management — View user information terminal commands
command | effect |
---|---|
id [ user name ] | To view the user UID and GID Information |
who | View a list of all currently logged in users |
whoami | View the account name of the current login user |
1.passwd file
/etc/passwd Files store user information , from 6 It's a semicolon 7 Messages , Namely
- user name
- password (x, Means encrypted password )
- UID( User ID )
- GID( Group ID )
- User's full name or local account number
- Home directory
- Login using Shell, After login , Terminal commands used ,Ubuntu The default is dash
2.usermod
usermod Can be used to set user Of The main group / Additional group and Sign in Shell,
The main group : You usually specify when you create a new user , stay
etc/passwd
Of the 4 Column GID The corresponding groupAdditional group : stay
etc/passwd
The last column in represents the list of users for this group , Is used to specify the Additional permissions of the userBe careful :
After setting the user's additional group , need Login again to take effect
By default
useradd
The added user does not have permission to use sudo With root The identity of the person executing the command , have access tousermod -G sudo user name
command , Add users to sudo In additional groups
# Modify the user's primary group (passwd Medium GID)
$ usermod -g Group user name
# Modify the user's additional groups
$ usermod -G Group user name
# Modify user login Shell
$ usermod -s /bin/bash
3.which
- which Command to see where the command is executed
- Be careful :
/etc/passwd
File used to save user information , Unenforceable/usr/bin/passwd
Is a program for changing user passwords- cd This terminal command is built into the system kernel , There are no separate files , So with which Unable to find cd Command location
- bin and sbin
- stay Linux in , Most executable files are saved in /bin 、/sbin、/usr/bin 、/usr/sbin
- /bin(binary) Is the binary executable Directory , It is mainly used for specific applications
- /sbin(system binary) It is a binary code storage directory for system administrators , It is mainly used for system management
- /usr/bin(user command for applications) Some software installed later
- /usr/sbin(super user commands for applications) Some hypervisors for super users
4. Switching users
command | effect | explain |
---|---|---|
su - user name | Switching users , And switch directories | - You can switch the home directory of large users , Otherwise keep the position |
exit | Exit the currently logged in account |
- su No user name , You can switch to root , But not recommended , unsafe
- If it is in the current directory Input exit , will sign out Shell A terminal window
5. Modify file permissions
Serial number | command | effect |
---|---|---|
1 | chown | Modify the owner |
2 | chgrp | Modify the set of |
3 | chmod | Modify the permissions |
The command format is as follows :
# Modify file / The owner of the catalog
$ chown user name file name / Catalog
# Recursively modify files / Group of directories
$ chgrp -R Group name file name / Catalog
# Recursively modify file permissions
$ chmod -R 755 file name / Catalog
- Be careful :
- chmod When setting permissions , You can simply use three numbers to correspond to each other The owner / Group And others User's rights
- Use it directly
chomd +/- rwx file name / Directory name
You can modify file / Catalog Of read | Write | perform jurisdiction , But it can't be accurate to The owner | Group | other
边栏推荐
猜你喜欢
New cover of time: metauniverse will change everything
运行服务器端 Pycharm 提示: Already running
Solve the thirdscripterror error of wechat applet
英语四六级听力有线传输无线发射系统方案
物理层2.1
CTSI 现已登陆 Bitstamp
大喇叭疫情防控广播解决方案
Coinbase's top 10 forecasts for Web3 and encryption economy in 2022
Have a cup of coffee with the co-founder of cartesi
Wonderful! The description of meituan Octo distributed service management system is too clear
随机推荐
Wechat applet comprehensive case practice 2
两台服务器之间拷贝文件-scp方法
Solve problems encountered when compiling mosquitto
Network Accounting - layered structure, OSI communication process, tcp/ip model and 5-layer reference model
7-1虚拟机上安装SSH的详细步骤
Bash variable -- user defined variable
Pytorch, specify the problem of the graphics card
小区IP网络广播背景系统解决方案-基于局域网、专网或广域网传输
记录:问题1,电脑闪屏;问题2,电脑桌面图标双击没有反应
Cartesi mars 2022 Review
校园英语调频台在江西陶瓷工艺美术职业技术学院的应用
操场运动场室外扩声系统方案与功能分析
source insight打开时闪退的解决办法
regular expression
YOLO9000: Better, Faster, Stronger
Significance learning record of FFT in MATLAB
蓝桥杯-K倍区间
C# Winform开发 文件/文件夹的复制 剪切 粘贴
Neonatal, brain segmentation data
为什么独立企业主会接受 CTSI