Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker context how to use specific ssh key

Tags:

docker

I would like to use a docker context to contact a server via ssh. I have a number of different ssh keys on my local. How do I tell a context to use a specific key? I've tried:

docker context create test --docker "host=ssh://<username>@<ip-of-server>,key=C:/path/to/key"

but no dice, it always asks for a password. Is there a way to tell a docker context what ssh key to use?

like image 755
FatalCatharsis Avatar asked Sep 13 '20 08:09

FatalCatharsis


People also ask

How do I SSH to another Docker machine?

Docker is using your local SSH agent. Any keys loaded into your agent will be accessible for the connection: add the private key to the SSH agent on the machine from which you want to issue the docker commands; add the public key on the target Docker host machine, in the <username-home>/.ssh/authorized_keys

What are Docker secrets and how to use them?

By using Docker secrets we can have a generic image that uses local SSH keys. A secret is a blob of data, such as a password, SSH private key, SSL certificate, or another piece of data that should not be transmitted over a network or stored unencrypted in a Dockerfile or in your application’s source code.

What are the drawbacks of using SSH keys in a docker container?

The drawback here is additional complexity due to the machinery required to create and manage a keystore such as Vault by HashiCorp. For SSH key use in a stand-alone Docker container see the methods linked above and consider the drawbacks of each depending on your specific needs.

How do I connect to a docker-compose server?

Basic knowledge of docker compose is a must here. Since you will be accessing the server via SSH keys, you need to add the public SSH key of your local system to your host Linux server's directory where docker-compose file is located and keep the name "id_rsa.pub" just to be sure. I suggest using the linuxserver/openssh-server image.


1 Answers

The key you are trying to use in the example you provided refers to the TLS key.

Docker is using your local SSH agent. Any keys loaded into your agent will be accessible for the connection:

  • if not present already, install a SSH agent;
  • generate the SSH key pair;
  • add the private key to the SSH agent on the machine from which you want to issue the docker commands;
  • add the public key on the target Docker host machine, in the <username-home>/.ssh/authorized_keys
  • now try a regular SSH into the target Docker host(ssh <username>@<ip-of-server>). Accept the fingerprint. If you are not asked for a password, docker won't ask for it either.

Create and activate the docker context, then run a dummy docker command:

docker context create test --docker "host=ssh://<username>@<ip-of-server>"
docker context use test
docker ps
like image 119
Neo Anderson Avatar answered Nov 15 '22 05:11

Neo Anderson