2

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

2
  • 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...
    – Hastur
    Commented Nov 26, 2015 at 21:38
  • the container is debian and I modify the sshd config for root connection. Commented Nov 27, 2015 at 10:27

2 Answers 2

3

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!

0

For key authentication, the owner for /root/.ssh/ inside the container must be root.

If not then execute:

lxc exec mail01 -- chown -R root:root /root/.ssh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .