ubuntu安装openssh启用SSH登录服务器

默认情况下,ubuntu系统在安装完成之后,不会安装openssh相关的软件包,所有我们在远程ssh登录到ubuntu系统的时候会失败。

本文将会讲述如何来安装openssh相关软件包来解决无法远程ssh登录到ubuntu系统的问题。

1、执行下面的apt-get命令安装openssh相关软件包。

apt-get install openssh*

ubuntutest@ubuntutest:~$ apt-get install openssh*
E: 无法打开锁文件 /var/lib/dpkg/lock - open (13: Permission denied)
E: 无法对状态列表目录加锁(/var/lib/dpkg/),请查看您是否正以 root 用户运行?
ubuntutest@ubuntutest:~$ sudo apt-get install openssh*
[sudo] password for ubuntutest:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
注意,根据Glob 'openssh*' 选中了 'openssh-known-hosts'
注意,根据Glob 'openssh*' 选中了 'openssh-blacklist-extra'
注意,根据Glob 'openssh*' 选中了 'openssh-blacklist'
注意,根据Glob 'openssh*' 选中了 'openssh-sftp-server'
注意,根据Glob 'openssh*' 选中了 'openssh-server'
注意,根据Glob 'openssh*' 选中了 'openssh-client'
注意,根据Glob 'openssh*' 选中了 'openssh-client-ssh1'
openssh-blacklist 已经是最新版 (0.4.1+nmu1)。
openssh-blacklist-extra 已经是最新版 (0.4.1+nmu1)。
openssh-known-hosts 已经是最新版 (0.6.2-1)。
openssh-client 已经是最新版 (1:7.2p2-4ubuntu2.2)。
openssh-server 已经是最新版 (1:7.2p2-4ubuntu2.2)。
openssh-sftp-server 已经是最新版 (1:7.2p2-4ubuntu2.2)。
openssh-client-ssh1 已经是最新版 (1:7.2p2-4ubuntu2.2)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 128 个软件包未被升级。

2、查看sshd 服务是否启动,执行下面的命令

ps aux | grep sshd

ubuntutest@ubuntutest:~$ ps aux | grep sshd
root      1129  0.0  0.2  65520  5272 ?        Ss   10:23   0:00 /usr/sbin/sshd -D
root      1304  0.0  0.3  95400  7012 ?        Ss   10:24   0:00 sshd: root@pts/0

3、使用非root 用户来验证是否能够SSH远程登录到该Ubuntu系统

ubuntutest@ubuntutest:~$ ssh ubuntutest@localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:gy+Rueth1RoavXu2zvs230nZUiCSRIcQZvivSDixfn4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
ubuntutest@localhost's password:
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

128 个可升级软件包。
62 个安全更新。

Last login: Wed Aug  2 10:11:14 2017
ubuntutest@ubuntutest:~$
标签:SSHUbuntu 发布于:2019-11-14 10:20:30