在Ubuntu上安装SSH并启用root登录ssh(OpenSSH服务器)

时间:2020-07-27 12:59:24  来源:igfitidea点击:

安全shell(ssh)是使用来自远程位置的命令行管理Ubuntu的最常用和安全的方式。

在本教程中,我们将学习如何在Ubuntu Server /桌面操作系统上安装和配置SSH服务器。

在Ubuntu 18.04上安装OpenSSH服务器

Ubuntu的SSH服务器由OpenSSH-Server包提供。
如果尚未安装,则可以使用APT-Get Install命令在Ubuntu 18.04中安装OpenSSH-Server包。

要安装OpenSSH,请打开Ubuntu终端并执行:

sudo apt-get update
sudo apt-get install openssh-server

这将在Ubuntu系统上安装SSH服务器。

在Ubuntu上启动SSH服务器

OpenSSH服务器应在安装后自动启动,如果没有,请在Ubuntu 18.04上启动SSH服务器,我们使用SystemCtl命令。

sudo systemctl start ssh.service
sudo systemctl enable ssh.service

在Ubuntu 14.04中使用service命令启动SSH服务。

sudo service ssh start

在Ubuntu启用SSH根登录

默认情况下,Ubuntu中的SSH服务器不允许使用root用户名连接到服务器。
为了允许root ssh登录,我们需要在/etc/ssh/sshd_config文件中将prictrootlogin更改为yes。

首先,打开/etc/ssh/sshd_config文件。

sudo vim /etc/ssh/sshd_config

然后定位行PercilRootLogin指令,取消注释(删除前面的#)并将其值更改为“是”。

PermitRootLogin yes

然后,保存SSH配置文件并重新启动SSH服务器。

sudo systemctl restart ssh.service

或者

sudo service ssh restart

现在我们可以使用root用户帐户登录Ubuntu SSH服务器。