eugene-khyst / podman-testcontainers

The example of using Podman with Testcontainers in Java projects, that use Gradle on Ubuntu Linux and MacOS (both x86_64 and Apple silicon).
Apache License 2.0
41 stars 6 forks source link

Where is the ssh key file? #6

Open evansj opened 4 months ago

evansj commented 4 months ago

Hi Eugene, thanks for creating this repo.

ssh -i ~/.ssh/podman-machine-default

https://github.com/eugene-khyst/podman-testcontainers/blob/main/README.md?plain=1#L180

Where does this ssh keyfile come from? I'm running Podman 5.1.1 on an M1 Mac running macOS 14.5 and there is no such file. I can "ssh" to the podman machine using podman machine ssh but that command doesn't take the -L argument, so I can't set up the socket tunnel.

eugene-khyst commented 4 months ago

Have you run podman machine init <name>? Then I believe the generated key is located at ~/.ssh/<name>. Anyway, run ls ~/.ssh/ to see all keys. id_rsa is not what you searching. But some other key may be what you need.

evansj commented 4 months ago

It turns out that the answer was there all along, in the output to podman system connection list --format=json:

[
    {
        "Name": "podman-machine-default",
        "URI": "ssh://core@127.0.0.1:59492/run/user/504/podman/podman.sock",
        "Identity": "/Users/me/.local/share/containers/podman/machine/machine",
        "IsMachine": true,
        "Default": true,
        "ReadWrite": true
    },
    {
        "Name": "podman-machine-default-root",
        "URI": "ssh://root@127.0.0.1:59492/run/podman/podman.sock",
        "Identity": "/Users/me/.local/share/containers/podman/machine/machine",
        "IsMachine": true,
        "Default": false,
        "ReadWrite": true
    }
]

The Identity value is the actual ssh key:

❯ file /Users/me/.local/share/containers/podman/machine/machine
/Users/me/.local/share/containers/podman/machine/machine: OpenSSH private key
❯ ssh -i /Users/me/.local/share/containers/podman/machine/machine -p 59492 core@127.0.0.1
Last login: Wed Jul  3 12:01:41 2024 from 192.168.127.1
core@localhost:~$

I don't know why there's a difference in key file location between your system and mine, but now I can modify the command so it uses the file specified in the output.