Linux System Management (i)

Source: Internet
Author: User
Tags cpu usage

Linux Users

Linux is a multi-user task system. Each user account can belong to one or more groups. In the/etc/passwd. Store user account information

[Email protected] ~]# HEAD/ETC/PASSWD
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Sync:x:5:0:sync:/sbin:/bin/sync
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Halt:x:7:0:halt:/sbin:/sbin/halt
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

Each line in the file corresponds to an account. There are seven columns per line, and I'll say what the difference is.

    1. User name

    2. User password

    3. User ID

    4. Group ID

    5. User aliases

    6. User home Directory

    7. User shell

Can find a problem, that is, the user password is displayed as "X", in fact, the real encrypted password stored in the/etc/shadow, you can see

[Email protected] ~]# Head/etc/shadow
root:$6$dwez01ifo0l.hprx$. Qq67vbryygaeteyuyapunrjuasidskwwjrmo8.cv0/d3q9ynpxiir0iwewqen7dbnse50nzfx0vyf5s4jg26.:16250:0:99999:7:::
Bin:*:14790:0:99999:7:::
Daemon:*:14790:0:99999:7:::
Adm:*:14790:0:99999:7:::
Lp:*:14790:0:99999:7:::
Sync:*:14790:0:99999:7:::
Shutdown:*:14790:0:99999:7:::
Halt:*:14790:0:99999:7:::
Mail:*:14790:0:99999:7:::
Uucp:*:14790:0:99999:7:::

Each line has 9 paragraphs, analyzed under

    1. User name

    2. Masked password after encryption

    3. The last change date after encryption. Represents the number of days from 1970-1-1 to the present

    4. The minimum number of days the password is kept, 0 is unlimited

    5. How many days before the password must be changed

    6. How many days ahead of time before password expires

    7. The number of days after the password expires, the account is considered invalid

    8. Account expiration time. From 1970-1-1 to present

    9. Reserved flag, meaningless

Linux group information, stored in the/etc/group file.

[Email protected] ~]# Head/etc/group
Root:x:0:root
Bin:x:1:root,bin,daemon
Daemon:x:2:root,bin,daemon
Sys:x:3:root,bin,adm
Adm:x:4:root,adm,daemon
Tty:x:5:
Disk:x:6:root
Lp:x:7:daemon,lp
Mem:x:8:
Kmem:x:9:

There are four columns

    1. Group name

    2. Group password

    3. Group ID

    4. List of users in the group, separated by commas

The same password is stored in the/etc/gshadow

[Email protected] ~]# Head/etc/gshadow
Root:::root
Bin:::root,bin,daemon
Daemon:::root,bin,daemon
Sys:::root,bin,adm
Adm:::root,adm,daemon
Tty:::
Disk:::root
LP:::d AEMON,LP
Mem:::
Kmem:::

Managing Linux Groups

Add Linux Groups

Groupadd [-G < group id> [-O]] [-R] [-F] Group name

Parameters:

-G < group id> [-O] Specifies the group ID, when the-o parameter is not used, the group ID is unique

-R using this parameter is to establish a group ID of less than 499, that is, to establish a system group

-F does not return an error message when adding a group that already exists

When the group is added, Groupadd reads/etc/login.defs, which sets the scope of the new group ID, which by default is 500-60000. The group ID is generally considered to be a user group, and the group ID of less than 500 is the system group

Cases:

Add a user group named NewGroup

[Email protected] ~]# Groupadd newgroup

Modify a Linux Group

Root user modifies Linux group using Groupmod

Groupmod [-G < group id> [-O] [-n < new group name;] Group name

Parameters:

-G < group id> [-O] modifies the group ID to the specified value, and the group ID is unique when-O is not used

-N < New group name > change the group name of the target group to the new group name

Change the name of NewGroup to groupnew, group ID 50000

[Email protected] ~]# groupmod-g 50000-n groupnew newgroup

Delete a Linux group

Groupdel Group Name

[Email protected] ~]# Groupdel groupnew

Managing Linux Users

Add Users

Useradd

Parameters:

-D < Home directory > specify user home Directory

-g< Group name > Specify the group to which the user belongs

-g< Group name > Specifies the group to which the user belongs, you can specify multiple groups, separated by commas between organizations

-M Create user home directory

-p< password > Set user password

-s<shell> Specifying the user shell program

Create the user Leon, and specify the user group as the root group, and the shell as/bin/bash:

[Email protected] ~]# useradd-g root-s/bin/bash Leon

Set Password

[Email protected] ~]# passwd Leon

modifying Linux Users

Usermod Modifying users

Parameters:

-e< date > specified account expiration date in the format YYYY-MM-DD

-f< days > number of days after expiry of account, account is banned

Other parameters ibid.

Change Leon's Shell to/bin/abc and the owning group to bin

[Email protected] ~]# usermod-s/bin/abc-g bin Leon

Delete User

Userdel [-r] User name

-R means to delete all files in the home directory

Process Management

PS Show Current process

Ps-a Show All Processes

PS aux common Display system all processes and users

[[Email protected] ~]# PS aux
USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND
Root 1 0.0 0.0 19244 1424? Ss 11:47 0:02/sbin/init
Root 2 0.0 0.0 0 0? S 11:47 0:00 [Kthreadd]
Root 3 0.0 0.0 0 0? S 11:47 0:00 [migration/0]
Root 4 0.0 0.0 0 0? S 11:47 0:00 [ksoftirqd/0]
Root 5 0.0 0.0 0 0? S 11:47 0:00 [watchdog/0]
Root 6 0.0 0.0 0 0? S 11:47 0:00 [events/0]
Root 7 0.0 0.0 0 0? S 11:47 0:00 [Cpuset]
Root 8 0.0 0.0 0 0? S 11:47 0:00 [Khelper]
Root 9 0.0 0.0 0 0? S 11:47 0:00 [Netns]
Root 10 0.0 0.0 0 0? S 11:47 0:00 [Async/mgr]
Root 11 0.0 0.0 0 0? S 11:47 0:00 [PM]
Root 12 0.0 0.0 0 0? S 11:47 0:00 [sync_supers]
Root 13 0.0 0.0 0 0? S 11:47 0:00 [Bdi-default]
Root 14 0.0 0.0 0 0? S 11:47 0:00 [kintegrityd/0]
Root 15 0.0 0.0 0 0? S 11:47 0:00 [kblockd/0]
Root 16 0.0 0.0 0 0? S 11:47 0:00 [Kacpid]
Root 17 0.0 0.0 0 0? S 11:47 0:00 [kacpi_notify]
Root 18 0.0 0.0 0 0? S 11:47 0:00 [Kacpi_hotplug]

The 11-column output corresponds to: User name, process number, CPU utilization, memory usage, virtual memory footprint, memory resident, terminal, status, start time, run time, Run command

Running processes

Divided into the foreground process and the background process, run the foreground process, log in the system, at the shell prompt to output commands directly

Run the background process, add a & symbol

[Email protected] ~]# Find/-name "*.conf" >/tmp/result &
[1] 3230

As you can see, after executing this command, output [1] 3230, where 1 indicates the background process sequence number, and 3230 is the process number. You can use jobs to view the background program serial number and the performance:

[[email protected] ~]# jobs
[1]+ done Find/-name "*.conf" >/tmp/result

Indicates that it has been completed

One drawback of the above approach is that if you close the terminal, the process running in the background will be closed

You can use Nohup

[Email protected] ~]# nohup Find/-name "*.conf" >/tmp/result &
[1] 3241

Using at timing to execute commands

Just give me an example, it's too tired.

8:45 PM of 2010-08-16:

[[email protected] ~]# at 08:45 PM 081610

3 days later, 3 o'clock in the afternoon

[[email protected] ~]# at 3 PM +3 days

20 minutes later

[Email protected] ~]# at now + minutes

Afternoon of February 14

[Email protected] ~]# at noon Feb 14

You can view the at task with ATQ, delete a task ATRM + list Number

Crontab perform tasks on a regular basis

Use CRONTAB-E to edit the current user's cycle execution tasks

Grammar:

< minutes > < hours > < > < months > < weeks > Commands

Example:

Every minute of every day of every month, the LS command is executed:

* * * * * ls

If you want to execute LS every 20 minutes,

* * * * ls

Number 1-10 per month, every 20 minutes, LS

* 1-10 * * ls

Use Crontab-l to view all crond tasks

You can use Crontab-r to delete all crond tasks for the current user

The root user can specify the user through the-u parameter, then modify the user's Crond task, and modify the Crond task of the Leon user.

[Email protected] ~]# crontab-e-u Leon

Adjust the process priority level

High-priority processes will have more CPU usage time, and the opposite of lower priority. The priority is represented by numbers from 20 to 19. -20 is the highest priority and 19 is the lowest priority. View Priority Ps-elf

Use nice [-number] [command [parameters]]

Such as:

[[email protected] ~]# nice--20 sleep 1000

If you do not specify a priority number, the command priority is 10

[[email protected] ~]# Nice sleep 1000

To adjust the priority while the process is running

Use the Renice command to adjust the precedence, syntax, when the process is running:

Renice priority number [[-p] Process number] [[-G] Group name] [[-u] User name]

Terminating a process

Kill [-S signal |-P] [-a] [--] process number

Kill-l Signal

Parameters:

-s< signal > Develop signals to be sent

-P displays only the process number

-L signal List

[Email protected] ~]# kill-l
1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill 5) SIGTRAP
6) SIGABRT 7) Sigbus 8) SIGFPE 9) SIGKILL) SIGUSR1
One) (SIGSEGV) (SIGUSR2) sigpipe) sigalrm) SIGTERM
Sigstkflt) (SIGCHLD) Sigcont SIGSTOP) SIGTSTP
(Sigttin) Sigttou () Sigurg) sigxcpu) Sigxfsz
(SIGVTALRM) sigprof) sigwinch SIGIO) SIGPWR
Sigsys) (sigrtmin) sigrtmin+1) sigrtmin+2 Notoginseng) sigrtmin+3
sigrtmin+4) sigrtmin+5 (sigrtmin+6) sigrtmin+7) sigrtmin+8
sigrtmin+9) (sigrtmin+10) sigrtmin+11 () sigrtmin+12) sigrtmin+13
(sigrtmin+14) sigrtmin+15 () SIGRTMAX-14) SIGRTMAX-13) SIGRTMAX-12
SIGRTMAX-11) SIGRTMAX-10 SIGRTMAX-9) SIGRTMAX-8 () SIGRTMAX-7
(SIGRTMAX-6) (SIGRTMAX-5) SIGRTMAX-4) SIGRTMAX-3) SIGRTMAX-2
SIGRTMAX-1) Sigrtmax

If the signal name/signal number is added after the kill-l, the corresponding signal digital/signal name will be output

[[email protected] ~]# kill-l Kill
9
[Email protected] ~]# Kill-l 9
KILL

End Process

End of 6223 process

Kil 6334

In fact, the default send 15 of the signal, and sometimes 15 of the not, will use 9 force to end the signal, this is very powerful

Kill-9 23342

This article is from the "IT Walker Pine" blog, please be sure to keep this source http://520yatou.blog.51cto.com/6642882/1435031

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.