If you forget your LXC container’s password, you can reset it from within the LXC host
1- chroot into the containers filesystem
chroot /var/lib/lxc/vm51/rootfs
2- issue the passwd command and enter the new password for the container
3- type exit to get back to the LXC host prompt
Another way is to simply fire the container up, then run
lxc-attach -n vm51
then execute the passwd command like you normally do, then the exit command
It is very important to understand that if you don’t have something such as fail2ban on your server, it could be that someone had bruit-forced into your container and changed the root password, in that case, i would completely recommend deleting the whole container and re-creating it from scratch
The reason is that we don’t know what the attacker (if any) had installed inside the system