Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用LXC 3.x在ubuntu中尝试ssh时权限被拒绝(公钥)_Ssh_Lxd - Fatal编程技术网

使用LXC 3.x在ubuntu中尝试ssh时权限被拒绝(公钥)

使用LXC 3.x在ubuntu中尝试ssh时权限被拒绝(公钥),ssh,lxd,Ssh,Lxd,我有VirtualBox Linux 4.15.0-36-generic#39 Ubuntu SMP周一9月24日16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux 我已经安装了LXD 3.x linux容器,我已经在它们上面创建了三个ubuntu类型容器的实例: +------+---------+----------------------+ | NAME | STATE | IPV4 | +------+--

我有VirtualBox Linux 4.15.0-36-generic#39 Ubuntu SMP周一9月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连接时出错。我已在主机环境上执行了以下设置:

我运行了ssh keygen,结果如下:

~/.ssh/id_rsa
~/.ssh/id_rsa.pub
我已附加到“db1”实例,如下所示:

sudo lxc exec db1 /bin/bash
然后,我在db1框中导航到
/etc/ssh/sshd\u 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机器

以下是我自己解决问题的方法:

1) (主机)登录到来宾db1实例:

sudo lxc exec db1 /bash/bin
2) (来宾)添加新的远程用户“james”

adduser james
3) (来宾)编辑/etc/ssh/sshd_配置文件

PasswordAuthentication yes
PasswordAuthentication no
systemctl restart sshd
4) (Guest)重新启动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_配置文件

PasswordAuthentication yes
PasswordAuthentication no
systemctl restart sshd
9) (主机)使用PKI将ssh连接到来宾系统

ssh gest_ip

***成功

以下是我主动解决问题的方法:

1) (主机)登录到来宾db1实例:

sudo lxc exec db1 /bash/bin
2) (来宾)添加新的远程用户“james”

adduser james
3) (来宾)编辑/etc/ssh/sshd_配置文件

PasswordAuthentication yes
PasswordAuthentication no
systemctl restart sshd
4) (Guest)重新启动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_配置文件

PasswordAuthentication yes
PasswordAuthentication no
systemctl restart sshd
9) (主机)使用PKI将ssh连接到来宾系统

ssh gest_ip
***成功