我有VirtualBox Linux 4.15.0-36-Generic#39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU / Linux。
我已经安装了LXD 3.x linux容器,并在其上旋转了三个ubuntu类型的容器实例:
+------+---------+----------------------+
| NAME | STATE | IPV4 |
+------+---------+----------------------+
| db1 | RUNNING | 10.81.188.179 (eth0) |
+------+---------+----------------------+
| web1 | RUNNING | 10.81.188.27 (eth0) |
+------+---------+----------------------+
| web2 | RUNNING | 10.81.188.7 (eth0) |
+------+---------+----------------------+
试图建立到db1服务器的ssh连接。我已经在主机env上执行了以下设置:
我运行了ssh-keygen,结果如下:
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
我已经这样附加到'db1'实例:
sudo lxc exec db1 /bin/bash
然后我在db1框上导航到/etc/ssh/sshd_config
文件,并设置了PasswordAuthentication yes
参数,然后重新启动了lxc实例
回到主机节点,我尝试使用以下命令在远程来宾节点上复制/设置公钥:
ssh-copy-id -i ~/id_rsa.pub james@10.81.188.179, and
ssh-copy-id -i ~/id_rsa.pub 10.81.188.179
...均不成功。这是日志:
james@james-virtualbox:~/.ssh$ ssh-copy-id -i ~/.ssh/id_rsa.pub james@10.81.188.179
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/james/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
james@10.81.188.179: Permission denied (publickey).
为什么不将密钥添加到远程db1机器...?!
答案 0 :(得分:1)
这是我根据自己的意愿解决的方法:
1)(主机)登录到来宾db1实例:
sudo lxc exec db1 /bash/bin
2)(来宾)添加新的远程用户“ james”
adduser james
3)(来宾)编辑/ etc / ssh / sshd_config文件
PasswordAuthentication yes
4)(来宾)重新启动sshd守护程序
systemctl restart sshd
5)(主机)使用userid / pwd SSH到来宾计算机
ssh james@guest_ip
***在这一点上,我有一个有效的userid / password ssh解决方案,但是我想将过去的userid / password转到公钥身份验证解决方案中,所以我接下来要做的是:
6)(主机)将公用密钥复制到来宾计算机
ssh-copy-id guest_ip
7)(主机)再次连接到访客计算机:
sudo lxc exec db1 /bash/bin
8)(来宾)删除密码验证。编辑/ etc / ssh / sshd_config文件
PasswordAuthentication no
systemctl restart sshd
9)(主机)使用PKI将SSH传输到来宾系统
ssh gest_ip
***成功