A, ZSH

1. The ZSH switching

First, ensure that the local terminal shell is ZSH. See weekly summary issue 27 for changes

2. ZSH configure the alias of the connection server

This short article is to solve such a small problem: buy ECS, get a public IP, know the password.

You don’t want to type SSH [email protected] each time in sheel to connect to the server.

At this point you can change the.zshrc configuration file (vi ~/.zshrc). Add the following statement to the configuration file: alias ssh_liugezhou=” SSH [email protected]

After the changes are complete, run the source ~/.zshrc command. This time in the terminal directly enter :ssh_liugezhou, then enter the server password.

2. Server information

Data disks and disk space

If I buy the new data set, data set needs additional mount, didn’t buy cases, the default is to mount a system disk, system disk is used to install the operating system, if the web application runs in system tray, once the reshipment system, all site data will be lost, if mounted on the data plate, can improve security, reshipment system user data is not lost, Run the fdisk -l command to check whether there are data disks. If there is only one Disk /dev/xvda, no new data disks exist.

The command to view disk space is df -h

3. Configure root user management

1. Add a user

Create a new user liugezhou using the command. Useradd Liugezhou can see the user name under /home after adding the user. Then enter passwd Liugezhou to set the password for the user. Press Enter to enter the password of the user (twice).

2. Delete the user

Syntax: userdel [-rf] liugezhou userdel can delete user accounts and related files. If no parameter is specified, only user accounts can be deleted, but related files cannot be deleted. -r: deletes the user login directory and all files in the directory. -f: Forcibly delete the user (this option takes effect even when the user is logged in to Linux)

3. View user information (UID, GID, group)

id liugezhou

4. Add the sudo permission to the new user

Add liugezhou ALL=(ALL) ALL

5. Switch users

su username

6. Relevant documents

/etc/passed file: user configuration file that records user information. /etc/shadow file: password configuration file /etc/group file: group configuration file, which records information about groups contained in Linux.

7.Management of more Linux users and user groups

4. Configure local password-free SSH login

1. Check whether the private key and public key have been configured on the local PC.

Go to the CD /Users/liumingzhou directory and check whether the directory contains id_rsa and id_rsa.pub. If the directory does not contain id_rsa, run the following commands in sequence: mkdir .ssh cd .ssh ssh-keygen -t rsa -b 4096 -C “[email protected]” eval “$(ssh-agent -s)” ssh-add ~/.ssh/id_rsa

2. Configure the configuration in the server root directory

Log in to the server, switch to the /root directory, and check whether the. SSH directory exists. If not, perform Step 1. After: SSH /authorzed_keys. Chomd 600 authorzed_keys sudo service SSH restart Enter ssh_liugezhou directly to log in to the server.

5. Change the default login port of the server.

The default port for logging in to Linux is 22[0-65536]. Ports 0-1024 are not used as much as possible because they may be occupied by the system. Vi /etc/ssh/sshd_config You can change the Port field or PermitRootLogin(whether root is allowed to log in).

Configure iptables and Fail2Ban to enhance security protection.

I will not summarize.

7. Whether the ECS server sets the connection timeout period

When an SSH client is used to connect to a Linux server, the session connection with the server is often interrupted. This problem is caused by the unique session connection mechanism of the SSH service. ClientAliveInterval 60 ClientAliveCountMax 86400 The ClientAliveInterval option defines how many seconds a signal is sent to the SSH client; The ClientAliveCountMax option defines the number of seconds after the SSH client is disconnected. 2. Restart the system SSH service service service SSHD restart Cloud server ECS Linux CentOS 7 Operation, but through systemctl operation.

  • View systemctl status sshd.service
  • Start: systemctl start sshd.service
  • Restart: systemctl restart sshd.service
  • Automatic: systemctl enable sshd.service

Make nodeJS service permanent with PM2

After the server downloads PM2, if you want to start an app.js project (this file contains a section of code to connect to the HTTP service); If you use Node app.js, exit the file or close the terminal, the file is no longer accessible. Use pm2. Pm2 startup item: pm2 app.js PM2 startup list: pm2 list Pm2 View information: pm2 show app View PM2 online logs: pM2 logs Stop service: pm2 stop app

tip

In terminal or VSCode or idea, if you want to move the cursor back to the beginning of the line, you can use CTRL + a and back to the end of the line, CTRL + e.

If you have any questions, please add my wechat id: 18231133236. Welcome to exchange! For more, please visit my personal blog: www.liugezhou.online. You can also follow my personal account: [Dangerous Wakaka]