How to enable SSH in Ubuntu

A virtual machine demo is used here, ubuntu version 22.10

1. Enable SSH when installing ubuntu

When installing ubuntu, you will be prompted whether you need to install OpenSSH server

 If you check the installation here, you don’t need to use the command to install OpenSSH server

2. Use the command to install and enable SSH

01. Switch the root user, if the root user password is not set, you need to set the root password first

sudo passwd root

The following will be displayed, enter as prompted

[sudo] password for unhan: # 输入当前用户密码
New password: # 输入root新密码
Retype new password: # 再次输入root密码
passwd: password updated successfully # 密码更新成功

At this point, the root user password has been set successfully, enter

su root

Enter the root password just set, after switching to the root user, it means that the password is set successfully

 02. Update source list 

sudo apt-get update

03. Install openssh-server

sudo apt-get install openssh-server

 Here you need to enter y, which means OK

04. Check whether the ssh service is started successfully

sudo ps -e | grep ssh

If there is sshd, it means that the ssh service has been started. If not, enter the following command to start the ssh service

sudo service ssh start

Enter the command to check whether the service is started again

So far, the ssh service has started normally

disable ssh command

sudo systemctl disable --now ssh

enable shh command

sudo systemctl enable --now ssh

05. Check the ip address ifconfig of the machine. If net-tools is not installed, you need to install it first. The command is as follows

sudo apt-get install net-tools

 After the installation is successful, enter ifconfig 

Here is the current system ip

3. Use the ssh tool to connect

01. Use Xshell to connect to ssh

 

 

 

 

 If the root user logs in, it will prompt failure

Need to modify the configuration file

vi /etc/ssh/sshd_config

Find PermitRootLogin and remove the # in front of it, and modify it to yes

before fixing

 after modification

 Save and restart the ssh service

sudo service ssh restart

After restarting the service, you can use the three-party tool to connect to ssh normally. If it is not normal, try restarting the machine

Guess you like

Origin blog.csdn.net/zhimi520/article/details/128826192