Skip to content

Instantly share code, notes, and snippets.

@khoipro
Last active March 25, 2024 19:32
Show Gist options
  • Save khoipro/f86c2b93da969ea383607ffd2b5d3c1b to your computer and use it in GitHub Desktop.
Save khoipro/f86c2b93da969ea383607ffd2b5d3c1b to your computer and use it in GitHub Desktop.
Hardening Runcloud VPS

Hardening VPS in Runcloud

Change SSH port

Step 1: Visit Dashboard > Choose Server > Security

Add New Rule
Globally Open Port, port 2040 (or your port)
Protocal: TCP

Save a rule.

Click a button "Deploy"

Step 2: Visit SSH terminal, edit file /etc/ssh/sshd_config and change row #Port 22

Port 2040
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

Save a file after changes.

Restart a service

service ssh restart

Step 3: Update Fail2Ban with new SSH port

  • Edit /etc/fail2ban/jail.local
[sshd]
enabled = true
logpath = %(sshd_log)s
port = 2040

Step 4: Remove old ssh port 22

Visit a Dashboard > Chooser Server > Security again, remove port 22 and click Deploy again.

Update MySQL config

# Backup my.cnf

cd /etc/mysql/
cp -r my.cnf my.cnf.bak

Edit file my.cnf

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

# Start custom settings

[mysql]
port = 3306

[mysqld]
skip-name-resolve = 1
table_definition_cache = 2000

performance_schema = ON

innodb_buffer_pool_size = 8G
innodb_buffer_pool_chunk_size = 1G
innodb_log_file_size = 1G

max_connections = 100000
max_user_connections = 1000
wait_timeout = 300
connect_timeout = 20

[mysqldump]
quick
max_allowed_packet = 2048M
general_log = on
general_log_file=/var/log/mysql/mysql.log

Save file.

Restart a service:

systemctl restart mariadb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment