Introduction

LXD (pronounced “Lex-Dee”) is a system container manager build on top of Linux Containers (LXC) supported by Canonical. The goal of LXD is to provide an experience similar to a virtual machine but through containerization rather than hardware virtualization. Compared to Docker for delivering applications, LXD offers nearly full operating-system functionality with additional features such as snapshots, live migrations, and storage management.” – By Simos Xenitellis 

So we got that introduction about LXD. Creating multiple virtual machine containers from LXD using Google Cloud instances will just get a local IP and you cannot connect to those containers outside or not available from the internet. Take a look at this screenshot.

Those are the IP’s of my LXD containers and I created those from GCP (google cloud platform). The problem is I cannot connect using SSH to those IP’s because they are just local IP’s created by LXD.

Solution: Create a proxy device using LXD proxy device command (only available in LXD version 3 and up)

Run this command from your host:

lxc config device add testssh proxyport2222 proxy listen=tcp:0.0.0.0:2222 connect=tcp:localhost:22                     

Generate an SSH Key from your local machin (I am using windows) then add it to your config file. You can use this Kinsta guide on how to properly generate an SSH key

Host 34.96.177.142
    User root
    Hostname 34.96.177.142
    PreferredAuthentications publickey
    IdentitiesOnly yes
    IdentityFile ~/.ssh/lxd1

Please note that the other hosts in my config file is for my other ssh connection so I just inserted that new host (External IP address of my GPC Virtual Machine)

Copy the public key from your local machine, login to that LXC as root, go to .ssh folder, edit the authorized_key file, paste the public key.

After that you should be able to connect to SSH to the LXC ‘testssh’. Screenshot below shows I am now connected as [email protected]

To remove the proxy device from that LXC container ‘testssh’, you can use this command.

lxc config device remove testssh proxyport2222

Subscribe To Our Newsletter

Join our mailing list to receive the latest website layout designs, news and updates from our team.

You have Successfully Subscribed!

Share This