1

I have 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.

I've installed LXD 3.x linux containers I've spun up three instances of ubuntu type containers on them:

+------+---------+----------------------+
| NAME |  STATE  |         IPV4         |
+------+---------+----------------------+
| db1  | RUNNING | 10.81.188.179 (eth0) |
+------+---------+----------------------+
| web1 | RUNNING | 10.81.188.27 (eth0)  |
+------+---------+----------------------+
| web2 | RUNNING | 10.81.188.7 (eth0)   |
+------+---------+----------------------+

In trying to establish ssh connection to db1 server. I've performed the following setup on the host env :

I've run ssh-keygen which resulted in the following:

~/.ssh/id_rsa
~/.ssh/id_rsa.pub

I have attached to the 'db1' instance like this:

sudo lxc exec db1 /bin/bash

I have then navigated on the db1 box to the /etc/ssh/sshd_config file and I've set the PasswordAuthentication yes parameter, and then I restarted the lxc instance

Back on the host node, I've attempted to copy/set the public key on the remote guest node using the following command:

ssh-copy-id -i ~/id_rsa.pub james@10.81.188.179, and
ssh-copy-id -i ~/id_rsa.pub 10.81.188.179

... both unsuccessful. Here is the log:

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).

Why won't it add that key to the remote db1 machine... ?!

JamesD
  • 679
  • 10
  • 36

1 Answers1

6

Here is what I did to solve it on my own accord:

1) (Host) Login to guest db1 instance:

sudo lxc exec db1 /bash/bin

2) (Guest) Add new remote user 'james'

adduser james

3) (Guest) Edit /etc/ssh/sshd_config file

PasswordAuthentication yes

4) (Guest) Restart the sshd daemon

systemctl restart sshd

5) (Host) ssh to the guest machine using userid/pwd

ssh james@guest_ip

*** At this point, I had a working userid/password ssh solution, but I wanted to advance past userid/password to the public key authentication solution, so this is what I did next:

6) (Host) Copy public key to the guest machine

ssh-copy-id guest_ip

7) (Host) connect to the guest machine again:

sudo lxc exec db1 /bash/bin

8) (Guest) Remove the password authentication. Edit /etc/ssh/sshd_config file

PasswordAuthentication no
systemctl restart sshd

9) (Host) ssh to the guest system using PKI

ssh gest_ip

*** Success

JamesD
  • 679
  • 10
  • 36