简体   繁体   English

使用lxc用户通过SSH连接到lxc容器

[英]Connecting to lxc container via SSH using lxc user

I noticed that the username/password I use to connect to a newly created LXC container via lxc-console doesn't work with ssh (with sshd running in the container). 我注意到,我用于通过lxc-console连接到新创建的LXC容器的用户名/密码不适用于ssh(在容器中运行sshd)。 When I try, I get Permission denied Why is that, and how can I make it work? 当我尝试时,我被Permission denied这是为什么?如何使它起作用?

inside container, open /etc/ssh/sshd_config and change PermitRootLogin to yes. 在容器内,打开/ etc / ssh / sshd_config并将PermitRootLogin更改为yes。

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

Do you allow passwords for SSH? 允许使用SSH密码吗? Do you have an iptables rule for port forwarding from your host to the LXC container IP address? 您是否有用于从主机到LXC容器IP地址的端口转发的iptables规则? You can add one with the following line (change port to your container's ssh port): 您可以在下面一行添加一个(将端口更改为容器的ssh端口):

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 1234 -j DNAT --to 10.x.x.x:1234

A newly created LXC container using the ubuntu-cloud template comes with the SSH daemon configured to not allow passwords: 使用ubuntu-cloud模板新创建的LXC容器带有配置为不允许密码的SSH守护程序:

To fix this, attach to your container and edit the /etc/ssh/sshd_config file. 要解决此问题,请附加到您的容器并编辑/ etc / ssh / sshd_config文件。 Look for the following: 查找以下内容:

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no

And change PasswordAuthentication to "yes" and restart SSH: 并将PasswordAuthentication更改为“ yes”,然后重新启动SSH:

service ssh restart

Then you should be able to log in to your container with a password. 然后,您应该能够使用密码登录到您的容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM