Enable SSH on Ubuntu

Google Cloud Google Cloud Enable SSH service on Ubuntu

how   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.

在 Ubuntu 上启用 SSH

Configure SSH service

In the virtual machine instance of the Google Cloud operating platform, click SSH and click Open in a browser window.

在 Ubuntu 上启用 SSH-1

 After logging into the server, switch to administrator mode

sudo -i

Then set a root administrative password

passwd

在 Ubuntu 上启用 SSH-1Update the system and install openssh-server

sudo apt update && sudo apt upgrade -y sudo apt install openssh-server

在 Ubuntu 上启用 SSH-1Once the installation is complete, the SSH service will be automatically started. You can verify that SSH is running by typing:

sudo systemctl status ssh

在 Ubuntu 上启用 SSH-1Ubuntu 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.

The 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

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

Just change PermitRootLogin to yes.

在 Ubuntu 上启用 SSH-1Then restart the ssh service

sudo systemctl restart ssh

Configure swap partition

Linux swap partition (), 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 content, 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

在 Ubuntu 上启用 SSH-1After installing CyberPanel 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

在 Ubuntu 上启用 SSH-1Next, 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

在 Ubuntu 上启用 SSH-1Next 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 # or directly write echo "vm.swappiness=80" >> /etc/sysctl.conf # Reload the parameter sysctl -p

在 Ubuntu 上启用 SSH-1turn onComes with TCP :

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

4. 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

Or you can use BBRPLUS below

BBRplus acceleration

The script contains three versions: BBR/BBR modified version kernel, BBRplus version kernel, and Lotserver (Rapid Speed) kernel.

wget -N --no-check-certificate "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh

 

related suggestion

CyberPanel Linux Hosting Panel - Simple, fast and open source control panel with OpenLiteSpeed ​​support

CyberPanel installs WordPress and configures pseudo-static rules

5/5 - (3 votes)

One comment

Leave a Reply

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