Linux Security Basics: shell and some basic commands, linuxshell

Source: Internet
Author: User

Linux Security Basics: shell and some basic commands, linuxshell

1. What is shell?
Shell is the interface between the user and the Linux operating system.
There are multiple shells in Linux, where Bash is used by default.

2. shell Classification
(1) bash
Bash shell is a free version of Bourne shell. It is the earliest Unix shell, including many additional features. Bash has an editable command line that allows you to check History commands. You can add the tab key to avoid entering long file names.
(2) csh
C shell uses the "Class C" syntax and draws on many features of the Bourne shell, but the internal shell command set is different.
(3) ksh
The syntax of the Korn shell is the same as that of the Bourne shell, and it is easy to use. Many installation scripts use ksh. Even if you do not use it as your main shell, you should install it in the system.
(4) tcsh
TC shell is an enhanced version of C shell, which is fully compatible with C shell.
(5) zsh
Z shell is an enhanced version of Korn shell and has many features of bash shell.

3. shell Basics
(1) The default shell of Redhat Linux is bash.
(2) Use $ as a prompt for a common user and # As a prompt for a Super User.
(3) view the shell supported by the current system: cat/etc/shells
(4) view the current bash version: echo $0
(5) view the current shell version: bash -- version

4. How to Use the shell Console
(1) What is the "console" console?
The console is a man-machine interface that uses the character operation interface.
(2) operation Console
Linux generally has 6 virtual consoles
Press Ctrl-Alt-(F1-F6) to select the virtual console. F2 to F5 is the command line interface, and F1 is the graphical interface.
After switching from a console to a new virtual console, linux will first display a logon prompt, just like the first login. Before loading another command interpreter, you will also ask for the user name and password. Therefore, we can log on to different consoles as different user identities, making it easier to perform specific operations with specific identities. After a user switches from a virtual console to a new virtual console, the program running on the original console will continue to run.
(3) Advantages of the virtual console
When a process fails to lock the input, you can switch to another virtual console to terminate the process.
(4) If you want to prevent the system from logging on to the image and directly entering the character state after the startup, you can modify the/etc/inittab file as follows (operations under KDE ):
The vim/etc/inittab file displays the following content:
# Inittab This file describes how the INIT process shocould set up
# The system in a certain run-level.
# Author: Miquel van Smoorenburg,
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
# Default runlevel. The runlevels used by RHS are:
#0-halt (Do NOT set initdefault to this)
#1-Single user mode
#2-Multiuser, without NFS (The same as 3, if you do not have networking)
#3-Full multiuser mode
#6-reboot (Do NOT set initdefault to this)
Id: 5: initdefault:
Change 5 in the last line to 3 to allow the system to log on without a graph. I will also introduce several other numbers:
0: stopped (do not set it to the default startup level)
1: single-user mode
2: multiple users, no NFS (If you do not configure the network, this level is the same as 3)
3: full multi-user mode
4: Do not use
5: graphic mode
6: restart (do not set it to the default startup level)

5. System Logon Process
BIOS boot phase: load the boot manager from the MBR and run the boot management.
Take GRUB as an example to start the boot phase: Read the/boot/grub. conf file and display the boot menu
Kernel stage: mount the root file system
Sys V init initialization phase: Start the/sbin/init program and read the/etc/inittab file.

6. Basic commands
(1) ls command
Ls-a to view hidden files starting with. And General Files
Ls-l to view more detailed file information, you can view file permissions.
Ls-F adds a symbol after the listed file or directory name. For example, if the executable file is added with *, the directory is added /.
(2) cd command
Command to access the directory.
Cd ~ Return to the home Directory
Cd-Return to the previously operated directory
Cd .. go back to the previous directory
Cd/return to the root directory
Cd.../back to the last two levels of directory
(3) mkdir command
Create a file
Mkdir-p/abc/bc/a multi-layer Directory Creation
Touch 1.txt creates a txt file named 1
(4) rmdir command
Delete an existing empty directory
(5) Move the music video directory or rename the file
Mv/tmp/xx.txt/rootmove the xx.txt file in the tmpdirectory to the root directory
Mv xx.txt yy.txtrename xx.txt as yy.txt
(6) cp command
Copy a file or folder
Target cp-r source file
For example, cp/abc/1.txt/cd copies the 1.txt file in the abcfolder to the cd file.
-R is recursively copied together with sub-directories.
(7) rm command
Delete a file
The rm-I system will ask if we want to delete the file.
Rm-r is deleted along with the subdirectory
Rm-f force delete file without confirmation
(8) cat command
Displays or links common ascii text files
Cat a.txt displays the contents of the.txt file.
Cat a.txt B .txt displays the contents in a.txt B .txt in sequence.
Cat a.txt B .txt> c.txt combines the content of a.txt B .txt with the content to redirect to c.txt.
Cat-n display row number
Cat-B empty rows do not show row numbers
Cat-A display Tab
Head-n 5 ip.txtdisplay the first five lines in the ip.txt File
Tail-n 5 ip.txtdisplay the last five lines in the ip.txt File
Pwd displays the current path
More: displays common text files. Better than cat.
(9) user and user group management commands
Create and delete users
Useradd username-p 123
Userdel Username
Create and delete a group
Groupadd group name
Groupdel group name
Passwd Password Change
Super Users can change passwords of other users
Other passwd user names
(10) Difference between su-and sudo
Su: environment variables are not changed. They are not root environment variables. Exit the current user identity exit.
Su-: Switch all. The root environment variable is used.
Sudo: temporarily raise the command permission
(11) Summary of File Permissions
User Host group other Others
R is the read permission and the value is 4.
W is the write permission and the value is 2.
X is an executable permission with a value of 1.
Rwx is readable and writable and executable.
Rws temporarily improves permissions for execution.
Rwt readable and writable files cannot be deleted.
(12) chmod command
Command for modifying directory or File Permissions
Chmod u + x ip.txt add executable commands to the ip file.
Chmod-R recursive weighting or downgrading
(13) process and task management commands
Ps command-the most basic and powerful process view command
Ps-e displays all processes
-F full format
-L long format
Top Command ----- dynamically display process information
Zombie botnets and dead processes
Wa I/O read/write
Id CPU idle Space
Kill command ----- Delete Process
Kill-q force Delete
Killall httpd deletes all httpd Processes
(14) disk and file system management commands
Df view disk Utilization
-K: displays the remaining disk space of the current disk.
-H is displayed as compliant with human reading habits
View the file size in du


Related Article

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: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.