我有 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) |
+------+---------+----------------------+
Run Code Online (Sandbox Code Playgroud)
尝试与 db1 服务器建立 ssh 连接。我在主机 env 上执行了以下设置:
我运行了 ssh-keygen ,结果如下:
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)
我已像这样附加到“db1”实例:
sudo lxc exec db1 /bin/bash
Run Code Online (Sandbox Code Playgroud)
然后我在 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
Run Code Online (Sandbox Code Playgroud)
……都没有成功。这是日志:
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).
Run Code Online (Sandbox Code Playgroud)
为什么它不将该密钥添加到远程 db1 机器...?!
以下是我自行解决的方法:
1)(主机)登录来宾db1实例:
sudo lxc exec db1 /bash/bin
Run Code Online (Sandbox Code Playgroud)
2)(来宾)添加新的远程用户“james”
adduser james
Run Code Online (Sandbox Code Playgroud)
3)(访客)编辑 /etc/ssh/sshd_config 文件
PasswordAuthentication yes
Run Code Online (Sandbox Code Playgroud)
4) (Guest) 重新启动 sshd 守护进程
systemctl restart sshd
Run Code Online (Sandbox Code Playgroud)
5)(主机)使用 userid/pwd ssh 到访客计算机
ssh james@guest_ip
Run Code Online (Sandbox Code Playgroud)
*** 此时,我有一个有效的用户名/密码 ssh 解决方案,但我想将用户名/密码推进到公钥身份验证解决方案,所以这就是我接下来要做的:
6)(主机)将公钥复制到访客机器
ssh-copy-id guest_ip
Run Code Online (Sandbox Code Playgroud)
7) (Host) 再次连接客机:
sudo lxc exec db1 /bash/bin
Run Code Online (Sandbox Code Playgroud)
8) (Guest) 取消密码验证。编辑 /etc/ssh/sshd_config 文件
PasswordAuthentication no
systemctl restart sshd
Run Code Online (Sandbox Code Playgroud)
9)(主机)使用 PKI ssh 到访客系统
ssh gest_ip
Run Code Online (Sandbox Code Playgroud)
*** 成功
| 归档时间: |
|
| 查看次数: |
5362 次 |
| 最近记录: |