- install software:
apt-get install <appName>
whereis <appName>
: View the software installation location;wget <web:url软件下载地址>
: Download the software installation package through the network;apt --purge remove <appName>
: Uninstall the software
-
ssh
The installation starts:sudo apt-get install ssh
sudo systemctl start
- View
ssh
startup status:ps -aux|grep sshd
- View
2.1 安装 `openssh` 服务端 : `sudo apt-get inistall openssh-server`;
启动: `sudo /etc/init.d/ssh start`
查看启动状态: `ps - e |grep ssh`
- 注意: 启动完成后需要将配置文件 `/etc/ssh/ssh_config` 中的 ‘# PasswordAuthentication yes’ 前的 `#` 号删掉,然后重启服务器;
-
View the ip address:
ifconfig
-
File editing:
- `i` 编辑模式; - `I`: 在当前光标所在行的行首,转换为输入模式; - `a`:在当前光标所在字符的后面,转换为输入模式; - `A`:在光标所在的行尾,转换为输入模式; - `o`:在当前光标所在行的下方,新建一行,并转为输入模式; - `O`:在当前光标所在行的上方,新建一行,并转为输入模式; - `s`:删除光标所在字符; - `r`:替换光标处字符;
esc
command mode;
-v
VISUAL mode (select text),y
end selection;
-d
cut line
- Cursor movement:
n+
: move down n lines;n-
: move n lines up;gg
: move to start;
- delete:
dd
: delete the current line;dG
: delete all content after the cursor;
- Page turning command:
ctrl + f
: turn down one page;ctrf + b
: turn up one page;
- Close the document:
x
: save the current document and exit;q
: quit;w
: save the document;q!
: Exit VI/VIM without saving the file;
- Replace source
Source list file location:/etc/apt/sources.list
5.1 Backup source list:cp /etc/apt/sources.list /etc/apt/sources.list.bak
;
5.2 Open source file:sudo vim /etc/apt/sources.list
;
5.3 Replace source file content (Ali source, you can continue to Baidu if you want others):
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
5.4 Save and exit: esc
:x
5.4 Refresh source path: sudo apt update
;
-
Check the ip address:
ifconfig
-
Reset role password:
sudo passwd username
-
Root remote login:
8.1 Open the ssh configuration filesudo vi /etc/ssh/sshd_config
8.2 CommentPermitRootLogin without-password
this sentence (no matter if there is no);
8.3 AddPermitRootLogin yes
; -
The cd (change directory, modify directory) command uses:
cd ~
: Jump to the root directory of the current user;cd -
: Jump back to the previous directory;cd
: Equivalent tocd ~
- The ls command uses:
ls
: view the files in the current directoryls <path>
: View the files under the path <path>;ls -a
: View all files (including hidden files) in the current directory, all files or folders.
starting are hidden files;ls -l
: List the detailed information of the file;ls -al
: List detailed information of all files;ls -h
: File information is displayed in KMGT format;
- The meaning of each value in the detailed information of the file:
-
alias
Alias the command:alias
: View all alias commands;alias la='ls -a'
: Givels -a
the command an alias namela
, and the two commands have the same effect at this time;- Adding an alias to the command line is temporary. When the current terminal is closed, the alias will be gone; if you want it to be effective for a long time, you can modify the alias configuration file;
unalias la
: delete alias la;
-
Folder and file related commands:
mkdir name
: Create a foldername
named ;mkdir /path1/path2/name -p
: In the path2 folder under the path1 file, create a folder named name;rmdir name
: remove a空
folder ;touch filename
: Create a file, there can be multiple;cp test..txt /path/test.txt
: Copy the test.txt file (folder) to the /path/ folder;cp test..txt /path/ttt.txt
: Copy the test.txt file (folder) to the /path/ folder, and rename it to ttt.txt;mv test..txt /path/test.txt
: Cut the test.txt file (folder) to the /path/ folder;rm -rf name
: Used to delete the file (folder) named name
-f
: No prompt, no prompt if an error occurs;
-r
: Recursive delete;*.txt
: fuzzy match a certain type of file-
:rm -rf *.txt
delete all
-
vim configuration file:
/etc/vimrc
: The configuration set for all users, the configuration that all users can read;~/vimrc
: The configuration set for the current user, only the current user can read;
-
Linux configuration file:
- A file that will be executed every time the terminal is opened;
/etc/bashrc
: Valid for all users;~/bashrc
: Valid for the current user;
- A file that will be executed every time the terminal is opened;
-
User management related instructions:
useradd <username>
: To create a new user, generally you need to specify-s
the parameter as/bin/bash
;su <username>
: switch user;passwd <username>
: Set a password for the specified user;passwd
: Set a password for the current user;userdel <username>
: delete user;
--f
: force delete;
--r
: delete home directory at the same time;whoami
: View the currently logged in user name;sudo
: Execute commands with root authority;
- You need to configure the user in/etc/sudoers
the file before you can usesudo
the command;
-visudo
: Quickly open/etc/sudoers
the file and enter the editing state;vim /etc/passwd
: View current system and user information of all users;
用户信息示例: root:x:0:0:root:/root:/bin/bash
解析: <用户名>:<用户密码:占位符>:<用户id>:<分组id>:<用户根目录位置>:<用户登录时执行的脚本>
- `vim /etc/shadow`: 系统所有用户密码文件;
用户密码示例: sshd:*:19262:0:99999:7:::
解析: <用户名>:<用户密码>:<修改日期>:<密码不可修改的天数>:<密码需要修改的期限: 天>:<修改期限前N天发出警告>:<密码过期的宽限:天>
- <用户密码> 详解:
* 空表示密码为空, 不需要输入密码就可以登录;
* “*” 号表示账户锁定;
* “!” 号表示密码已过期;
* “$1$” 表明用 MD5加密;
* “$2$” Blowfish 加密;
* “$5$” SHA-256 加密;
* “$6$” SHA-512 加密;
vim /etc/group
: View all groups in the system;
实例: root:x:0:
15.1 Grouping:
- When creating a user, the system will automatically create a group with the same name as the user;
- groups
: Check which group the current user is in;
- groups <username>
: Check the group where the specified user is in;
- gpasswd -a <username> <group_name>
: Add the specified user to the specified group Among them;
- gpasswd -d <username> <group_name>
: delete and remove the specified user from the specified group;
- Group with root
permission :
* ubuntu: sudo group | admin group | root group;
* centos: wheel group | root group;
-
File (folder) permission management
chmod
:- parameter:
o
: Other;chmod o+w <filename>
: Add 'w' write permission to other users of the specified file;u
: owner;chmod u-w <filename>
: remove 'w' write permission for specified file owner;g
: Belonging group;chmod g-r <filename>
: Remove the 'r' read permission for the specified file's owning group (owner group);a
: all;chmod a+r <filename>
: specified file, all users, add 'r' read permission;- Permission types and their corresponding values:
r
: 4: readable;w
: 2: writable;x
: 1: ;- Example:
sudo chmod 777 <filename>
; - Example:
sudo chmod u=777 <filename>
; - Example:
sudo chmod u=rwx <filename>
;
- Permission types and their corresponding values:
- parameter:
-
Compression, decompression:
zip <文件(夹)名> <压缩包名>
: compressed files, folders;unzip <压缩包名>
: unzip;tar
-
nginx-related:
sudo apt install nginx
: nginx install;sudo systemctl start nginx.server
: Start nginx service;sudo systemctl stop nginx
: Close the software;vim /etc/nginx/nginx.conf
: nginx global configuration file;
-
Linux-based python environment management:
a.sudo pip3 install virtualenv virtualenvwrapper
: Install python environment management tools;
b.~/.bashrc
: Edit (add) configuration files;export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.6 #指定新虚拟环境默认的Python版本 export WORKON_HOME=~/.envs#指定创建的新的虚拟环境保存在哪个文件夹下 source /usr/local/bin/virtualenvwrapper.sh#执行virtualenvwrapper.sh 脚本
c.
mkvirtualenv test
: Create a virtual environmenttest
named and store it inWORKON_HOME=~/.envs
the configured~/.envs
folder ;
d.workon test
: Switch totest
the virtual environment;
e.deactivate
: Exit the virtual environment;
-
|
Pipeline:
convert the standard output of the previous statement into the standard input of the next statement; -
Redirect:
>
: write:* 如果文件不存在,则新建文件; * 如果文件存在, 则直接覆盖原文件; `sudo ps -aux > pid.txt`: 将所有查询出来的进程结果, 写入pid.txt文件中;
>>
addition:`sudo ls ./ > pid.txt`: 将 `sudo ls ./ ` 执行的结果,追加到 `pid.txt` 文件中;
- Classification:
>
Equivalent to1>
: standard output, the result of a correct execution;2>
: Error output, the result of executing an error;&>
: all output: standard output + error output;
- Classification:
-
Command aliases:
ln -s x fn1 fn2
:fn1
Give an alias namefn2
, at this time isfn1
completely equivalent tofn2
;
-
Install the database (mysql 8.0):
sudo apt install mysql-server
: After ubuntu 18.4, the system is not compatible with mysql5.7;
- Mysql 8.0 login:
-sudo vim /etc/mysql/debian.cnf
: Copydebian-sys-maint
the user 's password;
-mysql -u debian-sys-maint -p
: Press Enter to enter the password;
-alter user 'root'@'localhost' identified with mysql_native_password by '123456'
: Modifyroot
the user 's login password;
- Then you can useroot
the user to log in;