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 root@192.168.122.215 -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
22 Answers
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!
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