Linux common settings

zhaozj2021-02-16  85

1) Set password rules

System administrators can use Linux's own tools to set the password rule (the minimum length of the password, whether the special character, the password expire, etc.), run: LinuxConf at the menu "User Account" - "Policies" - " Password & Accent Policies settings.

2) Forgot how the super user password

It is a Linux boot disk or install your CD to launch your computer. Then find the root partition on your computer's hard drive, use the mount command to mount the partition, then modify the file / etc / shadow. Because when I start Linux from a floppy disk, I can be a root user without entering any password. In the password file, remove the encryption password of the root user, so the root password will be empty.

Truely most important user information is actually stored in the file / etc / shadow file. This file is relatively secure because only root users can read. In this file, each line contains nine fields: 1 Log in to the username 2 encrypted password 3 From January 1, 1970, the number of days of the last modified password is 4 minutes from the next change password 5 password regularly modified When the number 6 password is about to expire, notify the user in advance 7 The password expires to the user canceled days 8 password is canceled, the distance is 10 January 1, 1970. 9 Reserved field

For example, the root user in my / etc / shadow file looks like this: Root: $ 1 $ BUPBMLAZ $ 1G7.Evichyqaei0TLZP0f.: 11071: 0: 99999: 7: -1: -1: 134540356 When the password is After elimination, it looks like this: root :: 11071: 0: 99999: 7: -1: -1: 134540356 Now, root users have no password, so I can restart the computer, under the login login prompt, Enter "root", and you can only press Enter key for password prompts (no password). After the login is successful, you can use the following command to modify the root password: Passwd

3) Close or delete a user

Temporary closure (lock) a user account does not need to modify the password of the user. Just only need to add an asterisk "*" before the / etc / shadow file belongs to the user's row (password). The asterisk "*" means that the user does not allow login. When you want to return the user to normal, you only need to remove the asterisk "*", the user can return to normal. The following is an example of using the user peter in / etc / shadow: Peter: * $ 1 $ NARMEFM6 $ fha1puou422hisl5aggli /: 11193: 0: 99999: 7: -1: -1: 134539228 I can also use the following command to close the user account: Passwd peter -l Release the user using the following command: Passwd Peter -u

Delete Users and User Groups: UserDel DoomDErm Doomed_user_login_name - then delete the user from the other user group: usermod -g doomed_user_login_name doomed_user_login_name- Force Delete All files and subdirectory under the host's home directory:

Rm -fr / home / doomed_user_login_name

4) Let a background running process continue to run after you withdraw from the system

Use the command NoHUP (= no hungup), for example:

Nohup Make & This command may be compiled a big program.

5) How to execute commands (using AT "and" Batch "on a certain time

The AT command allows you to specify a specific date and time to run a program. For example, I can play music on my CDROM every morning: AT 7: 00cdplay in the above example, I entered "At 7:00" in the command line, then press Enter. Then, the AT command displays a "at>"

Mogue, then I entered "CDPlay" and then press Enter, and finally, I hold down at the same time.

with

End the input. If I follow

Press Enter, another "at>" prompt appear, I can then enter the program I want to run at 7 o'clock in the morning. Course

After the last input

.

As is like sending a file to the current input, telling the input.

complete. Don't press continuous

Two times, otherwise you will automatically exit the system.

You can use the following command to list the tasks currently in the task schedule:

AT -L

You can see the list of programs that are still waiting in the task schedule.

If you change your idea, you will definitely remove a program from the task scheduling table. Example:

ATRM 8 This command will delete a command number 8 in the task schedule. I can also arrange a program to run at a little time, such as: AT 23:55 12/31 / 00StartX

If you can't run the AT command, check if the task scheduling service (ATD) has been loaded (you can run NTSYSV using the root user). If the AT command is valid for the root user but is invalid for normal users, check if the file /etc/at.deny exists, and confirm that the file /etc/at.allow does not exist. This is the default setting for all users to run the AT command. If you want only the specified user to run the AT command, you can generate file /etc/at.allow and add the list of users to the file.

6) How to set "cron"

Want to know when CRON is awakened to start running its task, you can view / etc / crontab, for example: CAT / etc / crontab you will see content is as follows:

# Run-parts01 * * * * root run-parts /etc/cron.Hourly02 4 * * * root run-parts /etc/cron.daily22 4 * * 0 root run-parts /etc/cron.weekly42 4 1 * * * Root Run-Parts /etc/cron.monthly You can see four different CRON tasks: hourly, daily, weekly and monthly. You can modify it, or join your own task. The following describes how it works: the order of each column is as follows: Minute (0-59), Hours (0-23), Date (1-31), Month (1-12), Week (from 0-6 Represents Sunday to Saturday). "*" Indicates any valid value. In the above example, the "hour" task is running in the "first minute" of the clock, which is equivalent to once every hour. The task of "Daily" occurs at 4:02 daily clock, just once a day. The "weekly" task happens at 4:02 in Sunday morning. "Month" task happens at 4:42 each month. The operating script of this task is placed at the end of each row.

If you want to let the mission at 4 o'clock in the morning, you can change 4 to 12. Cron is awakened once a minute checks whether / etc / crontab has been modified, so you don't need to restart the cron program when you modify the file.

7) How to customize your own shell

On my computer, the command prompt looks like this: [Stan @ Marie Stan] $ _ here, "stan" is the user name, "marie" is the computer name, the second "stan" is my current Work catalog, and "_" represents the cursor. The prompt is set by the environment variable PS1. You can use the following command to display the current settings: ECHO $ ​​PS1 prompt system range (for all users in the system) setting in file / etc / bashrc, the following lines may contain: PS1 = "[/ u @ / h / w] / $ "

To customize the prompt, I can edit the file / etc / bashrc (root user) and enter any text you want within two quotes. Here are some special codes I may use: / u - Current user's username (= $ logname) / h - computer name (Hostname) / H - complete computer name / W - current work directory name / W - Current work command full path name / $ - for ordinary users display $, for superuser display # /! - Current command number / # - Current command number (command running under the current shell) / D - current Date / T - Current time (24-hour system) / T - Current time (12 hours), Bash 2.0 effective / @ - Current time (AM / PM format), Bash 2.0 Active / s - shell type / A - alarm Sound / J - User Tasks / N - New Row // - Slacks / [- Unmatched Character Start Sign /] - Unchecked Character End Sign / NNN - ASCII Character Corresponding Octa Number $ (Date) - Date (Output Current Date) Command Output or Other Commands

The following is an example of how to add color:

PS1 = "/ [/ 033 [1; 32M /] [/ u @ / h / w] / $ / [/ 033 [0m /]"

8) There is a special meaning of the shell: / '"` <> []? |; # $ ^ & * () =

Here are four different symbols: backslash (/), single quotes ('), double quotes ("), reverse single quotes (`).

· Anti-slope (/) means: close the special meaning of the back character

· Single quotes (') indicate: Closing the special meaning of all characters between two single quotes

· Double quotation marks (") indicates: Closing the special meaning of all characters between two double quotes, except for $` /

· Reverse single quotes (`) Represents: Tell the Shell First run the command between the two reverse single quotes, then get the result

Then pass the commands other than two single quotes. The same function can also be implemented through the "$" command, and

It may be more convenient.

For example, I can create a strange directory name called "*" by using "/" or "'" symbol:

MKDIR / *

Mkdir '*'

This shields "*" for the special meaning of the shell. If there is no "/", "*" means all files in the current directory.

9) Input Output Redirection

There are three most important input and output streams: Standard input (stdin), standard output (stdout), standard error (STDERR). They are default for the console ("console" means that the keyboard is used for input, the screen is used to output), but they can be redirected. Redirect standard output, you can use the ">" symbol, for example: DIR my_dir> fileListing.txt will redirect the standard screen output of the DIR command to the file file files, so there is no output on the screen. This file can be used to edit (such as using a Pico text editor) or merged into other files. Redirect standard errors, you can use Structural "2>", for example: DIR MY_DIR 2> ErrorListing.txt The above command will send the standard to the screen. If there is no error message, there will be no information written to the errorListing.txt file. If an error, there is nothing to output to the screen, and the file erroRLISTING.TXT will contain error messages. The error message is likely to be like this: Dir: my_dir: permission denied Finally, I can also output the standard output and standard errors to the same file, DIR my_dir> file_and_error_listing.txt 2> & 1 The above command is first redirected to the standard output to In the text file, then redirect the standard error to the same location in the same location. How it implements may seem a bit weird, but it is feasible. In the above example, if the redirected file already exists, the file will be overwritten. If you want to add to the end of the file, you can use the ">>" symbol, the above example becomes: DIR MY_DIR >> FileListing.txtdir my_dir 2 >> ErrorListing.txtdir my_dir >> file_and_error_listing.txt 2> & 1 If you I feel confused about "2>", there is a simple way to help you understand, standard flowing standard parser: "0" represents standard input, "1" represents standard output, "2" represents standard errors.

Dir my_dir> file.txt is a shorthand method of the following command: DIR my_dir 1> file.txt The following command is used to output standard error: DIR my_dir 2> file.txt, you can also use symbols "|" Command) Send a command output to the standard input of another command. In the following standard, the standard output of the DIR command is entered into the command more by the pipe (automatically pause when the output is full screen): Dir | More You can also use the "Tee" command to write standard output to files and screens DIR | TEE FILELISTING.TXTTEE is an analog tone of the "T-type connector", and the main use in the pipe is diverted. This part is used to describe the standard output redirection, which is useful for standard input redirects, but it can be implemented using: Cat

10) Simplify the mount command with an alias

An alias is an abbreviation for more complex or more common commands. In order to create an alias, I as a super user, edit the / etc / bashrc file. Alias ​​in the system is valid for all users (in order to create an alias specified by the user, editing the relevant parts of my / etc / bashrc file in the user's home directory) My / etc / bashrc file is as follows: Alias ​​CDROM = "Mount -V / MNT / CDROM = "umount -v / mnt / cdrom" alias dosDrive = "mount -v / mnt / dosdrive" alias udosdrive = "umount -v / mnt / dosdrive" alias zipdrive = "mount -v / mnt / Zipdrive "alias uzipdrive =" umount -v / mnt / zipdrive "alias floppy =" mount -v / mnt / floppy "alias ufloppy =" umount -v / mnt / floppy "" - v "option represents" verbose ", ie: Tell Linux tells me more information when mount. In order to make the alias take effect, the user wants to log in. Now the user can use this simple command to mount the floppy disk: floppy he / she can use the following command to uninstall: ufloppy11) View important system log

CAT / VAR / LOG / SECURE

12) Creating an alias

Aliase Ls = "ls -color = TTY"

If you want all users on the system to always use this alias, write it to the / etc / bashrc file. Use UNALIAS Alias_name to delete an alias.

13) Common system management command

Setup (running in root) Configuring the mouse, sound card, keyboard, and system service. Many release suits have their own specific configuration utilities, and setup is the default configuration program of Redhat. Mandrake 7.0 offers very easy to use Drakconf. LinuxConf (running in a root user, on text mode or on the X terminal). Here you can access and change hundreds of network settings. The function is very powerful - do not change too much thing, change the project you don't know, must be careful. The RedHat Network Configuration Tool NetConf is a subset of LinuxConf, so it is relatively simple and mostly easy to use. MouseConf (running in root). A simple tool that configures the mouse (after completion of the initial installation). Mandrake also has a similar tool MouseDrake.

UserConf (Run User Run) menu-driven user configuration tool (password policy, group information change, increase user, etc.). It is part of the LinuxConf package, but can run separately.

转载请注明原文地址:https://www.9cbs.com/read-12818.html

New Post(0)