Docker - Restoring Target certificates after a system re-install

Due to issues with which i will to not bore you i have had to completely rebuild my main development machine.

Fortunately all my important data is backed up to the cloud so has been restored.

One issue i have is that 2 projects are docker based using Digital Ocean

I have selected the project from its folder but get an error “cant find files ca.pem, cert.pem and keys.pem”

I expected to be able to go back into the target settings, refresh the remote droplets and reset the certificates.

So I open the target settings

Clicking “Test” shown the below error

If i click “Manage” (and refresh) no docker machines are listed

Before I mess around and potentially take down two large live sites can anyone advise how i can restore the certificates and re-gain access to the droplets

Well losing your local keys and docker machine definitions, can be challenging to recover.

Happily someone has written an article for that:

https://medium.com/codelit/adding-existing-digital-ocean-droplet-to-docker-machine-93dfb28e1d96

Thanks George, will give it a try.
Life with FTP was so much easier :grinning:

1 Like

Quick question if i may. If i screw this up am i in danger of losing the droplet contents. I am really concerned about this possibility

Well that’s a great start to the day.

Don’t really understand the guide (dont forget i am a Microsoft man, Linux is not something i use day to day)

Logged into console, opened config file (sudo vim /etc/ssh/sshd.config)

No PasswordAuthentication line in config., dont know if i should add it or if I am in the wrong place

Looking further down the guide i don’t even understand most of it, it is clearly written for someone with Linux experience which is not me

So now i am locked out of my two main current projects, no idea how to fix them and feeling quite sick

#iwillneverusedockeragain

Well loosing the docker machine settings is like loosing your ftp password- so it does needs a bit more recovery. But it should be all doable fine with your digital ocean admin and keys.

Let me check more in detail the procedure.

Perhaps but ftp passwords etc are stored in Wappler’s config and are also easily changed/ reset.
I assumed all docker settings would also be stored in a config file within the project… I have no idea I had to start backing up docker settings separately before reinstalling my machine

1 Like

Well the recovery procedure turned out to be not that simple. So use it in extreme cases only.

Here is the docker machine recovery procedure more explained.

Always create a snapshot backup first

Before starting doing dangerous things like this always create a snapshot of your server first, so you can easily just restore it if something bad goes wrong.

You can do that easily in the Digital Ocean admin panel.

Using SSH Keys

Just for the info, login in to remote servers (ie droplets) is currently done with SSH and SSH keys as passwords.

So to fully access your server, you just need it to let it know your SSH key. You usually generate one single SSH key for your self that you use on all your servers.

Your own SSH key

So first step is to create your own SSH key if you don’t already have one. It is usually stored in ~/.ssh/id_rsa (where ~ is your user folder)

The key consist of two parts, private and public, private is file with just the name: id_rsa and public is the file id_rsa.pub

So the public you need to upload to your server to get it to knows you.

To generate your own key you can:
for Windows:

For Mac:

Accessing your droplet

If you don’t have a root password for this droplet, you need to reset it first - do note this will shortly reboot your droplet.

If you got a new password per email - just use ctrl+v to paste it, it works in the console

Then you can call the console and login in it.

Adding your SSH key

So to let the server knows your self, you need to add your SSH public key to its text file called ~/.ssh/authorized_keys

The easiest way to do this, when you are logged in on a terminal is to copy and paste that.

So just open your own local id_rsa.pub that you might have generated above, in a text editor locally and copy its contents first.

it looks something like:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx user@yourpc

So then go back to the server console and start with echo " then paste the key with ctrl+v:

and add " >> ~/.ssh/authorized_keys

so the totaly should look like:

echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx user@yourpc" >> ~/.ssh/authorized_keys

this will add your key at the end.

To check you can enter:

cat ~/.ssh/authorized_keys

and you should see your key at the end

So now your key is known to the server, so you can login with any ssh terminal to it directly.

But also you can now create the docker-machine import

Creating a new docker machine config based on your server

So now that your server knows about your and you can access it with SSH, we can recreate the docker machin config.

So go to your user folder .ssh and open a terminal (or powershell there.

Check if you have the docker-machine command available by typing it:

docker-machine

We only need the docker-machine command for the recreation of the config, so if you don’t have it, download it from https://github.com/docker/machine/releases/ and place it in the current folder. Make sure it is called docker-machine (with .exe if you are on windows). You can delete it afterwards when done.

Then enter:

docker-machine create --driver generic --generic-ip-address=YOUR_DROPLET_IP --generic-ssh-user root  --generic-ssh-key id_rsa YOUR_DOCKER_MACHINE_NAME

where your_DROPLET_IP is the ip adress of your droplet and the YOUR_DOCKER_MACHINE_NAME is how the docker machine used to be called.
\As you are in the .ssh folder, this will use your current id_rsa key that you assigned in the steps above.

Note: your docker machine name should be exactly the same as it used to be.

This will reconnect with docker on your server and reinstall it. Existing data will be kept.

Deploy again.

To get your server fully running again, you need to open your wappler project and redeploy it

Once done - everything should be running as it should and you will have again full control.

Conclusion

You should always make backup of your docker machines settings. Those are the keys to your servers. They are located in ~.docker/machine/machines (where ~is your user folder)

1 Like

Thanks @George, I will give it a try later when my massive headache :grinning: clears

Would it be possible to add some sort of keys backup into Wappler in future so if needing to rebuild (or change) a system the keys could be restored automatically?
I am sure this will happen to many others at some stage if Docker take-up increases

Well there is a tool for this:

https://medium.com/@cweinberger/docker-machine-export-and-import-34ae2899e9d7

but we will see if we can integrate it more in the Wappler workflow

1 Like

At stage, adding SSH key:

I have generated RSA private and public keys with Puttygen but the private key is nothing like that shown in the guide:

PuTTY-User-Key-File-3: ssh-rsa
Encryption: none
Comment: rsa-key-20210518
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQC3WnNkZ1vj5qXfhbReFIZyvGQuG6ln82Ms
ZBqrKRw/LkjrODjZziPks3UdFF9dC9HG2PY8N+IJveXUiSlZhruXGuVNtcfb4V7H
wJiHyooAdoVbFKttdWirzCeNpgFbF9tyNXoZezn2ECtsoCyB8srGdg6QDo0mRm8G
UwmkDRtcDBznxWVCRJKMcM7ET2sY0Y1QZcoTVxTjrAUdaeEko/1vutkAu/mIkVN/
75UIhUrEHhZzifAKhehljSmXUPUkoRTEBp0OILp3JGfBa/+rKfWJ1J+LTslTH9pJ
FhGY047fyxXjNCfL/mF0hr3t4/PtP1RqyTbiQ3xkZwljAa8Bq5jf
Private-Lines: 14
AAABAQCPq6+JuDfXv46wNFud8KVdWGODgadfzeYjDZmcDs2UcFcxAVAC0zVq6nfV
PnZvOWi6UJ25l+xlx8hEnumovhtWDvwoxU0C7XjQOwkKNlmmfTiHow2k6oAHRiSk
KLUdRPduaZrwRo+nUQpFxsi5Vp8vnahRlyVhHYW3xe9i/eY3W+4QV+/KokzW3LMl
3aUMYupaaQkesoOSVm33z3LzQBsJr7p0humr09TQ9Rk5wZii6mIaYNrYaFCipzFS
tIxipjDWMMZjJ9bven/drkJLU3PS05DxD4+cSMlpI4tgeNSt3Bv1YnsfHF5iUCPl
t4rqYaX3PoxXQ8pN/Qx30tBP3N+RAAAAgQDosw7rXbRaWhKKIj72cptRSkCPSfMV
EUadSmKZZGwI4GGbsKzKGlQ5R/pi2cTb45axLZRNut3OGlzd1zasei4u7bLGduSK
wRb0RlfaidYhiXRZ8jMoNE25eImt1lsupNE9O1PV18ycOZFEDObexZSX6wQl9KL4
2054aW8cwuUVmQAAAIEAybZ4VMfnTpGvikl+t3MR4me6FQkr/sz3oxYGsXdpLohi
tJwmbMI3GN5hgu1T/X5K12nT2U98gf0uwCm81m+pX2HRTjBPwKBilwdVfWnXjwlB
8EzCMXrS6tdfi84N99bAY5AuC5ssSMszQqohXbVhcZBF3QJiYvlULQd5ftrSvTcA
AACAPnFDNqjncdYXVJ+nVmsYHRgyr11myateUlnQQAqPEg4lC6ub7Hl2mqqIt9Y5
zPSMReT6Fp3YSKXTJ81j5CUhqAEcx41U0sts9V8QtrstG3z6wFV2DXxFuf2cXsuB
4EClTpJ3QpyjO5R3uLgu0os0wIAVJV1CLH96+qPrrgQQPxc=
Private-MAC: 0311702612caecd7f864c9faa556e856a99d7b5a379764591e075957c0da5612

This is what i am doing for info:
image

From putty you can just get the public key by clicking on the buttons - no need to extra it from the file.

This is what i am doing (will add passphrases when i have this working)

Press Generate

image

save Private Key as id_rsa

image

Save Public Key as id_rsa.pub

image

This gives me:

rsa_pub (private)

PuTTY-User-Key-File-3: ssh-rsa
Encryption: none
Comment: rsa-key-20210518
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQCmHkzXR8S5tJSw0FG8VcBEdOIxasJ9U1UF
ao/WEiQBnnfa8qjJc3THzVg8RzDwskfqVrvYP/x7cvK4i21UHsPbDhZL9oo6HWmR
UkZ4AFgVTG0n1+Ux8nB6JMEm5Zw18XHTmPmq38Hvc+4vhG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K39r9Vv8BgiXDboc0A=
Private-MAC: c5ad4d110d40f1c30227be6720359115aab2c377e8ba8c2dbbcb34cb1adf4895

id_rsa.pub (public)

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20210518"
AAAAB3NzaC1yc2EAAAADAQABAAABAQCmHkzXR8S5tJSw0FG8VcBEdOIxasJ9U1UF
ao/WEiQBnnfa8qjJc3THzVg8RzDwskfqVrvYP/x7cvK4i21UHsPbDhZL9oo6HWmR
UkZ4AFgVTG0n1+Ux8nB6JMEm5Zw18XHTmPmq38Hvc+4vhGRBuV7Ro9rWQx7LgNdA
5g86uOUq/LlSERS2/fdSrcrZxm7EHTaaHD3EUVJIzzPlObkORV8McB+hTnXxfWWv
b9LP4Cnm11KOuo5himh8ez7pe7+oHZfla0CmwfvbvlgEr3kYrxPz3GUqyxhnOYVO
zFkolRLrncqo86ORiRvFnwmEklBajoKfTkgwjJCJ58/z6YNd/EYr
---- END SSH2 PUBLIC KEY ----

Loading the private key then re-saving public does not appear to have any effect of the contents / format of the public key.

Well maybe using putty is a bit too much.

The most standard way is just to use ssh-keygen command and it is also available on Windows as well.

Was just following your tutorial which specified Putty but will try ssh-keygen

2 posts were split to a new topic: Docker deploy error port is already allocated

That’s now possible and easier in Wappler 4.5.3 - you can connect to your existing remote target.

1 Like

This topic was automatically closed after 47 hours. New replies are no longer allowed.