ssh root@"ip of lxc container" don't work

7,689

If you are using LXC with the default bridged network, you have to define an iptables NAT rule that the traffic from host will be redirected to the container.

You can get the IP address of the specific container on host with:

lxc-info -n [containername] -i

Now execute this with root privileges on the host:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2222 -j DNAT --to [container ip address]:22

Now you can access your SSH server inside the container with:

ssh root@[host ip address] -p 2222

Be careful! This doesn't work if the SSH server inside the container doesn't allow root login over SSH!

Have fun!

Share:
7,689

Related videos on Youtube

Andrea di Paola
Author by

Andrea di Paola

Updated on September 18, 2022

Comments

  • Andrea di Paola
    Andrea di Paola over 1 year

    how can I enter in a lxc container using ssh? Because I follow many guide on that argument but I can't still enter in the container.

    [root@T410 andrea]# ssh [email protected] -vvvv
    OpenSSH_7.1p1, OpenSSL 1.0.2d-fips 9 Jul 2015
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 56: Applying options for *
    debug2: ssh_connect: needpriv 0
    debug1: Connecting to 192.168.122.215 [192.168.122.215] port 22.
    debug1: connect to address 192.168.122.215 port 22: Connection refused
    ssh: connect to host 192.168.122.215 port 22: Connection refused
    

    I don't understand why I can't enter in the container.

    thanks in advance

    • Hastur
      Hastur over 8 years
      Just some generic questions/checks: is there sshd on in the container? Does it accept root connection? Not in all the system is accepted the remote log in as root...
    • Andrea di Paola
      Andrea di Paola over 8 years
      the container is debian and I modify the sshd config for root connection.