报错如下
kai@ubuntu:~$ sudo apt-get install openssh-server
[sudo] password for kai:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
openssh-server : Depends: openssh-client (= 1:7.2p2-4ubuntu2.8)
Depends: openssh-sftp-server but it is not going to be installed
Recommends: ssh-import-id but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
分析
观察报错提示是依赖出错,于是我们看到如下:
The following packages have unmet dependencies:
openssh-server : Depends: openssh-client (= 1:7.2p2-4ubuntu2.8)
Depends: openssh-sftp-server but it is not going to be installed
Recommends: ssh-import-id but it is not going to be installed
解决
把依赖库处理好就ok,按照提示,安装openssh-client (= 1:7.2p2-4ubuntu2.8)
kai@ubuntu:~$ sudo apt-get install openssh-client=1:7.2p2-4ubuntu2.8
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
ssh-askpass libpam-ssh keychain monkeysphere
The following packages will be DOWNGRADED:
openssh-client
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 10 not upgraded.
Need to get 590 kB of archives.
After this operation, 369 kB disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-security/main amd64 openssh-client amd64 1:7.2p2-4ubuntu2.8 [590 kB]
Fetched 590 kB in 1s (787 kB/s)
dpkg: warning: downgrading openssh-client from 1:7.6p1-4ubuntu0.3 to 1:7.2p2-4ubuntu2.8
(Reading database ... 164030 files and directories currently installed.)
Preparing to unpack .../openssh-client_1%3a7.2p2-4ubuntu2.8_amd64.deb ...
Unpacking openssh-client (1:7.2p2-4ubuntu2.8) over (1:7.6p1-4ubuntu0.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up openssh-client (1:7.2p2-4ubuntu2.8) ...
Installing new version of config file /etc/ssh/moduli ...
Installing new version of config file /etc/ssh/ssh_config ...
再试一下安装ssh,ok,问题解决
kai@ubuntu:~$ sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
ncurses-term openssh-sftp-server ssh-import-id
Suggested packages:
ssh-askpass rssh molly-guard monkeysphere
The following NEW packages will be installed:
ncurses-term openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 4 newly installed, 0 to remove and 10 not upgraded.
Need to get 633 kB of archives.
After this operation, 5,136 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 ncurses-term all 6.0+20160213-1ubuntu1 [249 kB]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-security/main amd64 openssh-sftp-server amd64 1:7.2p2-4ubuntu2.8 [38.9 kB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-security/main amd64 openssh-server amd64 1:7.2p2-4ubuntu2.8 [335 kB]
Get:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 ssh-import-id all 5.5-0ubuntu1 [10.2 kB]
Fetched 633 kB in 1s (714 kB/s)
Preconfiguring packages ...
Selecting previously unselected package ncurses-term.
(Reading database ... 164028 files and directories currently installed.)
Preparing to unpack .../ncurses-term_6.0+20160213-1ubuntu1_all.deb ...
Unpacking ncurses-term (6.0+20160213-1ubuntu1) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../openssh-sftp-server_1%3a7.2p2-4ubuntu2.8_amd64.deb ...
Unpacking openssh-sftp-server (1:7.2p2-4ubuntu2.8) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../openssh-server_1%3a7.2p2-4ubuntu2.8_amd64.deb ...
Unpacking openssh-server (1:7.2p2-4ubuntu2.8) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../ssh-import-id_5.5-0ubuntu1_all.deb ...
Unpacking ssh-import-id (5.5-0ubuntu1) ...
Setting up ncurses-term (6.0+20160213-1ubuntu1) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Setting up openssh-sftp-server (1:7.2p2-4ubuntu2.8) ...
Processing triggers for systemd (237-3ubuntu10.29) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up ssh-import-id (5.5-0ubuntu1) ...
Setting up openssh-server (1:7.2p2-4ubuntu2.8) ...
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:HnigLnVY6ByA6AZoVU9xurr8DVL6FfuYyHQ8wPTTSHw root@ubuntu (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:uXxsDLHIWOnu9XZI0vGhnIzhLFrwes2Gey8iMii3J1k root@ubuntu (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:76Ggk5M7oFIFfY4DlfWCydM8lINYyoByYKCNzoq15ok root@ubuntu (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:mOJXMkXolZs6SmDlfvZy6b+VcsQ6jo5q7PbmeYvNKU4 root@ubuntu (ED25519)
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service.
Processing triggers for systemd (237-3ubuntu10.29) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...