Skip to content

Blog

Check Whether the Proxy Agent Is Running Normally

Use curl to send a request through the local proxy and print only the HTTP status code:

curl -so /dev/null -w "%{http_code}" google.com -x socks5://127.0.0.1:10080
  • socks5 is the proxy protocol. It can be replaced with another protocol such as http.
  • 10080 is the proxy port. Replace it with the input port of your proxy service.

If the command returns 301 or 200, the proxy service is working. If it returns 000, the proxy service is not responding and cannot be used normally.

[1]. Linux-Auto-PAC

SSH Configuration on a Server

1. Open the SSHD configuration file and enable the required authentication options

Section titled “1. Open the SSHD configuration file and enable the required authentication options”
$ vim /etc/ssh/sshd_config

Uncomment the relevant options. The resulting configuration should look like this:

Protocol 2
PermitRootLogin yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

Port: specifies port 22.

Protocol: specifies SSH protocol version 2.

PermitRootLogin: allows the root account to log in.

RSAAuthentication: enables RSA authentication.

PubkeyAuthentication: enables public key authentication.

AuthorizedKeysFile: sets the location of the user’s public key file.

$ service sshd restart

Because AuthorizedKeysFile is set to .ssh/authorized_keys, the file is stored under the target user’s home directory. If the target account is git, the path should be /home/git/.ssh/authorized_keys.

$ mkdir /home/git/.ssh

3. Change the owner of the directory to git

Section titled “3. Change the owner of the directory to git”
$ chown -R git:root /home/git/.ssh

Create an SSH key pair and specify RSA as the authentication algorithm. DSA is the older default algorithm on some systems.

$ ssh-keygen -t rsa

This creates a public key and a private key. If you do not change the path and do not set a passphrase, the files are usually saved under the current user’s .ssh directory as id_rsa and id_rsa.pub.

2. Import the client public key to the server

Section titled “2. Import the client public key to the server”

Replace IP with the server IP address:

$ ssh git@IP 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

3. Verify the key file on the server and adjust permissions

Section titled “3. Verify the key file on the server and adjust permissions”

After entering the git user’s password and importing the key successfully, return to the server, confirm that authorized_keys exists, and adjust permissions:

$ chmod 700 /home/git/.ssh
$ chmod 600 /home/git/.ssh/authorized_keys

4. Clone the repository again from the client

Section titled “4. Clone the repository again from the client”

Replace IP with the server IP address and update the repository path as needed:

$ git clone git@IP:/opt/code/test.git

5. Restrict the git user from logging in through an interactive SSH shell

Section titled “5. Restrict the git user from logging in through an interactive SSH shell”

Edit /etc/passwd:

$ vim /etc/passwd

Find the record for the git user and change the default /bin/bash shell to /bin/git-shell. The result should look like this:

git:x:1001:1001::/home/git:/usr/bin/git-shell

The default SSH port can be exposed to brute-force attempts. To improve security, consider changing it.

Following the first step, change the value after Port to XXX. Make sure it does not conflict with other services.

The firewall blocks ports by default, so open the new SSH port:

firewall-cmd --zone=public --add-port=XXX/tcp --permanent

On SELinux-enabled systems, SSHD may fail to start if SELinux is not configured for the new port.

semanage port -a -t ssh_port_t -p tcp XXX

  • XXX refers to the new port number in the examples above.

[1]. https://zhuanlan.zhihu.com/p/40371444

[2]. https://liqimore.com/2020/change-default-ssh-port-for-centos/

[3]. Linux-Firewall-初探

[4]. Yubikey-PIV-as-SSH-Key

[5]. Using-FIDO2-as-SSH-Authentication

Markdown basic syntax

  • Use = and - to mark first- and second-level headings
  • Use the # mark, and the first-level title corresponds to a #
  • paragraph Line breaks require two carriage returns

  • font
    italic text
    italic text Bold text Bold Text Bold italic text italic bold text

  • dividing line You can use more than three asterisks, minus signs, and underscores in a line to create a separator line. There can be no other things in the line. ***

    -–

  • strikethrough Add ~~ at both ends of the textGoogle.com

  • Underline Underline

  • footnote Format: [^famous text required] This is a text that requires footnotes 1

  • unordered list Can be marked with *, +, - * first item * Second item - first item - Second item + first item + Second item
  • ordered list Use numbers plus . to represent 1. first item 2. Second item
  • List nesting Add four spaces before sublist options 1. First * ele1 * ele2 2. second * ele3 * ele4

4. Markdown blockTo block a quote, use > at the beginning of a paragraph, followed by a space.

Section titled “4. Markdown blockTo block a quote, use > at the beginning of a paragraph, followed by a space.”

By using multiple >, multiple levels of nested references can be achieved

print()function

  • code block
    Use to wrap a piece of code, you can specify or not specify the language int main()
    ```javascript
    $(document).ready(function () {
    alert('RUNOOB');
    });

The image syntax format is as follows:

8. Markdown tablesWhen making a table, use | to separate different cells, and use - to separate the header and other rows.

Section titled “8. Markdown tablesWhen making a table, use | to separate different cells, and use - to separate the header and other rows.”
| 表头 | 表头 |
| ---- | ---- |
| 单元格 | 单元格 |
| 单元格 | 单元格 |
Header Header
cell cell
cell cell
  • Alignment * -: Set content and title bar to right alignment
    • :- Set content and title bar to left alignment
    • :-: Set the content and title bar to be centered
| 左对齐 | 右对齐 | 居中对齐|
| :-----| ----: | :----: |
| 单元格 | 单元格 | 单元格 |
| 单元格 | 单元格 | 单元格 |
left aligned Align right center alignment
cell cell cell
cell cell cell

[1]. https://www.runoob.com/markdown

  1. footnote content ↩