Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of linux users, permissions and shell commands

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the example analysis of linux users, permissions and shell commands. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

User group

View user-related files

[hadoop@hadoop ~] $ll / usr/sbin/user*-rwxr-x---. 1 root root 103096 Apr 7 2015 / usr/sbin/useradd-rwxr-x---. 1 root root 69560 Apr 7 2015 / usr/sbin/userdel-rws--x--x. 1 root root 42264 Aug 23 2010 / usr/sbin/userhelper-rwxr-x---. 1 root root 98680 Apr 7 2015 / usr/sbin/usermod

View files related to user groups

[hadoop@hadoop ~] $ll / usr/sbin/group*-rwxr-x---. 1 root root 54968 Apr 7 2015 / usr/sbin/groupadd-rwxr-x---. 1 root root 46512 Apr 7 2015 / usr/sbin/groupdel-rwxr-x---. 1 root root 50800 Apr 7 2015 / usr/sbin/groupmems-rwxr-x---. 1 root root 61360 Apr 7 2015 / usr/sbin/groupmod

(1) add users:

[root@hadoop ~] $useradd ruoze

(2) View the information of user ruoze:

[root@hadoop ~] $id ruoze

Uid=501 (ruoze) gid=501 (ruoze) groups=501 (ruoze)

(3) Delete a user:

For unclear commands, you can ask usedel-- help: learn to use the help command at work

[root@hadoop ~] $userdel ruoze

Because there are only ruoze users in this group of ruoze, when this user deletes, the group will verify himself and delete automatically.

(4) simulated switching between user loss styles

[ruoze@hadoop] $ll-atotal 28drwx-4 ruoze ruoze 4096 Nov 18 14:53. Drwxr-xr-x. 5 root root 4096 Nov 18 14:53.-rw-r--r-- 1 ruoze ruoze 18 Jul 24 2015 .bash _ logout-rw-r--r-- 1 ruoze ruoze 176Jul 24 2015 .bash _ profile-rw-r--r-- 1 ruoze ruoze Jul 24 2015 .bashrc

[ruoze@hadoop ~] $rm-rf .bash

# Open a new window to switch users [root@hadoop ruoze] # su-ruoze # switch ruoze users-bash-4.1 $# # user style missing # # Note: delete the configuration file of rm-rf .bash * in the previous step, resulting in a different restriction structure

Fixed style: copy all files under .bash * from skel and copy them to the desired directory.

[root@hadoop ruoze] # cp / etc/skel/.* / home/ruoze/cp: omitting directory `/ etc/skel/.'cp: omitting directory` / etc/skel/..'cp: omitting directory `/ etc/skel/.gnome2'cp: omitting directory` / etc/skel/.mozilla' [root@hadoop ruoze] # ll-atotal 28drwx4 ruoze ruoze 4096 Nov 19 09:40 drwxr-xr-x. 5 root root 4096 Nov 18 14:53.-rw-r--r-- 1 root root 18 Nov 19 09:40. Bash _ logout-rw-r--r-- 1 root root 17 Nov 19 09:40. Bash _ profile-rw-r--r-- 1 root root 124 Nov 19 09:40 .bashrcdr wxr-xr-x 2 ruoze ruoze 4096 Nov 12 2010 .gnome2drwxr-xr-x 4 ruoze ruoze 4096 May 6 2019 .Mozilla [root@hadoop ruoze] # [root@hadoop ruoze] # chown ruoze:ruoze .bash * # modify the user group to which the user belongs [root@hadoop ruoze] # ll-a # Command error details pay attention to bash: ll-a: command not found [root@hadoop ruoze] # ll- atotal 28drwx4 ruoze ruoze 4096 Nov 19 09:40 drwxr-xr-x. 5 root root 4096 Nov 18 14:53.-rw-r--r-- 1 ruoze ruoze 18 Nov 19 09:40. Bash _ logout-rw-r--r-- 1 ruoze ruoze 17 Nov 19 09:40. Bash _ profile-rw-r--r-- 1 ruoze ruoze 124 Nov 19 09:40 .bashrcdr wxr-xr-x 2 ruoze ruoze 4096 Nov 12 2010 .gnome2drwxr-xr-x 4 ruoze ruoze 4096 May 6 2019 .Mozilla [root@hadoop ruoze] #

(5) add ruoze users to another group bigdata

[root@hadoop ~] # groupadd bigdata [root@hadoop ~] # usermod-a-G bigdata ruoze # #-an append [root@hadoop ~] # id ruozeuid=501 (ruoze) gid=501 (ruoze) groups=501 (ruoze), 502 (bigdata)

(6) modify bigdata to the primary group of ruoze

[root@hadoop ~] # usermod-g bigdata ruoze # forcibly change the group or-- gid [root@hadoop ~] # id ruozeuid=501 (ruoze) gid=502 (bigdata) groups=502 (bigdata)

two。 Set password command: nothing is added after the passwd+ username or passwd is to change the current user's password

3. Switch users

Su ruoze

Su-ruoze

"-" means to switch the user's home directory and execute the environment variable file

The .bash _ profile file su ruoze will not be executed, su-ruoze will be executed

.bashrc file su ruoze execution, su-ruoze execution

# # Note: later configuration of personal variables is carried out in .bashrc

4. Ordinary users get the maximum permissions of root

Command line mode entry: vi / etc/sudoers

Locate the root user rights settings:

Root ALL= (ALL) ALL

Ruoze ALL= (root) NOPASSWD:ALL # No login password required

5./etc/passwd * * key points * * users exist but cannot be switched. That's why there is a problem here.

[root@hadoop ~] # vi / etc/passwd # # go to edit and change bin/bash to bin/false or sbin/nologin for testing ruoze:x:1002:1003::/home/ruoze:/bin/false # enter the format of / etc/passwd display # sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin#tcpdump:x:72:72::/:/sbin/nologin#hadoop:x:500: 500:hadoop:/home/hadoop:/bin/bash#ruoze:x:501:501::/home/ruoze:/bin/bash [root@hadoop] # su-ruoze Last login: Tue Nov 19 08:40:33 2019 # login failed [root@hadoop ~] #

Note: / etc/passwd file

Many components of CDH

Hdfs component hdfs user, hbase component hbase user, yarn component yarn user

Su-hdfs, su-hbase. If this command cannot be switched, it is / bin/false or / bin/false after bin/ in passwd.

You can solve the problem by changing it to / bin/bash.

6. Authority

Error: Permission denied

Chmod-R 777 folder / file path

Chown-R user: user group folder / file path

[root@hadoop~] # lltotal 4drwxr-xr-x 2 root root 6 Nov 16 22:15 ruozedata-rw-r--r-- 1 root root 18 Nov 16 21:58 rz.log first letter: d folder,-file, l connection rwxr-xr- xr: read 4w: write 2 x: execute 1mi: no permission 0

For example, 755 means

7 = rwx the first group 7 represents the root of the user of the file or folder, read, write, execute

5 = rmurx represents the user group root of the file or folder, read and execute

5 = rmurx represents the permissions of users belonging to other groups on this file or folder: read, execute

(1) order display

Chmod-R 777 folder / file path # # Note: 777 represents read-write execution permissions for any user group

Chown-R user: user group folder / file path

(2) case

/ tmp any [root@hadoop tmp] # echo "www.ruozedata.com" > > rz.log-rw-r--r-- 1 root root 18 Nov 16 22:33 rz.log# adds user useradd jepson [root@hadoop tmp] # useradd jepson [root@hadoop tmp] # su-jepson# to edit a temporary message [jepson@hadoop tmp] $vi rz.log# quits during work: ctrl+x/z generates swp file ll-a deletion Then .rz.log.swp # can be changed to read, Write (other groups) [root@hadoop tmp] # chmod 646 rz.log [root@hadoop tmp] # [jepson@hadoop tmp] $vi rz.log # Editing succeeded # add jepson user to the root user group [root@hadoop tmp] # usermod-a-G root jepson# permission to modify the second group of files: permission = "rw permissions [root@hadoop tmp] # chmod 664 rz.log [root@hadoop ~] # su-jepson [jepson@hadoop ~] $cd / tmp [jepson@hadoop tmp] $vi rz.log # editing is successful

7. View size command: du-sh

Du-sh + file

8. Search find

In the process of application, it can be matched with the "*" number for fuzzy matching.

This is the end of the article on "sample analysis of linux users, permissions and shell commands". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report