After installing Ubuntu 20.04, the root account cannot log in, and ssh cannot connect remotely.

I have been using the Ubuntu system recently, and found some regular things. Whenever the system is installed, I have to do some things, otherwise it cannot be used normally and smoothly. I will list these: (I will install the steps Save it, it’s relatively simple and just follow the wizard, just don’t minimize the installation)

1. Replace the apt source with Alibaba Cloud mirror source (it will be very fast when downloading the package)

2. Set a password for the root account and ensure that you can log in successfully

In ubuntu 20.04, the default is to log in to the virtual machine as an ordinary user. If the virtual machine needs to log in to the virtual machine as root. You need to log in as a common user first, and then use the command to switch to the root user. It is very inconvenient to operate and configure files on the desktop, so I teach you to use root to automatically log in to the desktop, so that the operating system is very convenient.

3. ssh remote connection

Then deal with it one by one, follow the steps to ensure that your Ubuntu is smooth and silky

1. Replace the apt source and replace the Alibaba Cloud mirror source

There are a lot of command replacements on the Internet. I will not talk about commands here. I will talk about how to operate and replace them on the graphical interface, and it will be done soon.

1. Graphical interface

1.1 Click the program list in the lower left corner of the screen and select  the Software & Updates  icon

1.2   Select  "Other..." in the "Download from" list box

1.3 In the pop-up dialog box, find  "mirrors.aliyun.com"

Some people may not have mirrors.aliyun.com, click select best server to download the source

 


1.4 Click the Choose Server button to take effect.

The source is now updated

Refer to this for manual configuration changes. 

https://blog.csdn.net/bluebird_shao/article/details/124357230

2. Set a password for the root account and ensure that you can log in successfully

1. Set root user password

Use the shortcut key Ctrl+Alt+T on the desktop to open the terminal emulator,
execute  sudo passwd root  , then enter the set password, enter it twice, and
complete the setting of the root user password

2. Modify the configuration file

Modify gdm-autologin and gdm-password

2.1 Execute sudo vim /etc/pam.d/gdm-autologin to comment out 

#auth required pam_succeed_if.so user != root quiet_success  line (about the third line)

 

2.2 Execute sudo vim /etc/pam.d/gdm-password to comment out

# auth required pam_succeed_if.so user != root quiet_success This line (about the third line)

 2.3 Modify the /root/.profile file

Execute sudo vim /root/.profile to modify the configuration file, add before the last line of the document

tty -s && changed to tty -s &&mesg n || true

3. Restart the system to make it take effect

https://blog.csdn.net/qq_34041694/article/details/121791033

3. Install openssh-server and maintain ssh remote connection

1. apt get openssh-serve

sudo apt-get install openssh-server

2. Start the sshd service

service sshd start


1. /etc/init.d/ssh start 
会出现[ ok ] Starting ssh (via systemctl): ssh.service.
 
2. /etc/init.d/ssh restart  : 重启ssh服务
 
3. /etc/init.d/ssh stop     : 结束ssh服务
 
 
以上还可以用
1. service sshd start
2. service sshd restart
3. service sshd stop
代替,但是开启和关闭没有提示

3. Modify root connectable permissions

vim /etc/ssh/sshd_config, modify this parameter to PermitRootLogin  yes

 4. Test whether ssh is normal

You can use finalshell or ssh localhost in the current session box. If you can connect normally after entering the password, it means that there is no problem with the connection.

If you can't connect, you can restart the sshd service

service sshd restart

https://blog.csdn.net/qq_39457834/article/details/114176049

All preludes are done! Then you can remotely operate and connect to your server, and then perform various operations!

Guess you like

Origin blog.csdn.net/Alex_81D/article/details/131512358