Enable SSH on Ubuntu

Google Cloud Google Cloud enables Ubuntu's SSH service

By default, when When initially installed, pass Remote access is not allowed. Enabling SSH on Ubuntu is very simple and straightforward.

Perform the following steps as root or another sudo user to install and enable SSH on your Ubuntu system.

Configure SSH service

existGoogle Cloudoperating platformvirtual machineIn the example, click SSH and click Open in browser window.

Enable SSH on Ubuntu

Update the system and install openssh-

sudo apt update sudo apt install openssh-server

Enable SSH on Ubuntu

Once the installation is complete, the SSH service will be automatically started. You can verify that SSH is running by typing:

sudo systemctl status ssh

Enable SSH on Ubuntu

Ubuntu comes with a firewall configuration tool called UFW. If a firewall is enabled on your system, make sure the SSH port is open:

sudo ufw allow ssh

enter sudo ufw status Press Enter to check the firewall status:inactive is closed,active is on.

use sudo ufw enable Turn on the firewall.

use sudo ufw disable Turn off firewall

If UFW is not enabled, you can ignore this step. Ubuntu turns off the firewall by default. If you need to turn on the firewall, please use the above command to turn it on.

linuxThe default SSH port is 22. For security reasons, it is necessary to modify port 22 to 60000;

The modification method is as follows:
exist /etc/ssh/sshd_config Find Port 22 and modify it to 60000.

If the user wants to open ports 22 and 60000 at the same time, just /etc/ssh/sshd_config Just modify the parameters within.

vi /etc/ssh/sshd_config

Basic parameters:

  • Port # port
  • PermitRootLogin yes # allows root authentication login
  • PasswordAuthentication yes # allows password authentication
  • RSAAuthentication yes # key authentication
  • PubkeyAuthentication yes

By default, root login and password authentication are turned off. You need to change the value after the parameter to yes.

Enable SSH on Ubuntu

Then restart the ssh service

sudo systemctl restart ssh

Configure swap partition

partition (swap), or memory replacement space (swap space), is an area on the disk, which can be a partition, a file, or a combination of them. The function of the swap partition is that when the system's physical memory is tight, Linux will save infrequently accessed data in the memory to the swap, so that the system has more physical memory to serve each process, and when the system needs to access the storage on the swap , and then load the data on the swap into the memory, which is often called swap out and swap in.

Ubuntu View current swap partition size

Enable SSH on Ubuntu

After installing on Ubuntu, the default Swap partition configured by CyberPanel is 2G, which is currently not enough. Let's take a look at how to expand the Sawp partition.

First check the swap partition mounting location:

cat /proc/swaps

Enable SSH on Ubuntu

Next, stop the default swap partition, delete the Swap partition, and then rebuild the Swap partition.

# Stop the Swap partition sudo swapoff /cyberpanel.swap # After stopping, use the free -m name to check whether the Swap has been stopped successfully. The free -m #swapon and swapoff commands are used to open or close the swap space (including swap files and swap partitions) respectively. # Delete swap Partition sudo rm /cyberpanel.swap

Enable SSH on Ubuntu

Next create a new Swap partition:

# Create a new 10G Swap swap partition sudo dd if=/dev/zero of=swapfile bs=1024 count=10000000 # Use the ll command to check whether the partition is created successfully # Set partition permissions sudo chmod 600 swapfile # Format the partition sudo mkswap -f swapfile # Enable partition sudo swapon swapfile # Check the new partition location cat /proc/swaps # Set boot echo '/root/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Make the swap partition permanent,vi /etc/fstab Modify the /etc/fatab file and change /swapfile none swap sw 0 0 Add at the end.

Adjust kernel parameters:

Kernel parameters .swappiness controls the relative weight of the memory when swapping out the runtime. The parameter value has a great relationship with how to use the swap partition. A larger value indicates more active use of the swap partition, and a smaller value indicates more active use of physical memory. The default value of general system swappiness=60 means that the swap partition will be used when the memory usage exceeds 100-60=40%. When swappiness=0, it means that the physical memory is used to the maximum extent, and then the swap space; when swappiness=100, it means that the swap partition is actively used and the data on the memory is moved to the swap space in a timely manner.

# Check the parameter value cat /proc/sys/vm/swappiness # If you want to temporarily adjust the parameter value, you can use the following command sysctl vm.swappiness=50 # Permanently adjust the parameter value vi /etc/sysctl.conf # in /etc/ Modify the parameter vm.swappiness=50 in the sysctl.conf file and reload the parameter sysctl -p in #

Enable SSH on Ubuntu

turn oncentosBuilt-in TCP BBR :

If the system comes with a kernel higher than 4.9, BBR is included by default.

Use root privileges to run the following code, and the kernel version is higher than 4.9.

uname -r

Turn on BBR:

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf

Use the following command to make the modified BBR take effect:

sysctl -p

Execute the following command. If the result contains bbr, it proves that your kernel has enabled bbr.

sysctl net.ipv4.tcp_available_congestion_control

Note: You can also execute the following command. If there is bbr in the result, it can also prove that your kernel has enabled bbr.

lsmod | grep bbr

related suggestion

CyberPanel Linux Hosting Panel – ​​Support Simple, and

CyberPanel installs and configures rules

uzbox
uzbox

Leave a Reply

Your email address will not be published. Required fields are marked *