Customize a CentOS LXC Container with Proxmox

SSH should be on by default

Table of Contents

The CentOS-based container template provided by Proxmox doesn’t have SSH installed, which makes it fairly useless for Ansible-based deployments.

Here are the steps to update and reroll a template:

Create and connect to the container

The web UI is easy and fills out important info for you, but I created it through the CLI using a template I had preloaded.

root@gold:~# pct create 105 gluster:vztmpl/centos-7-default_20171212_amd64.tar.xz --storage local-lvm --net0 name=eth0,ip=dhcp,ip6=dhcp,bridge=vmbr0 --password=password
root@gold:~# pct start 105
root@gold:~# pct console 105

Make desired changes

You can do pretty much anything, but keep it simple:

# Install packages
[root@CT105 ~]# yum -y update && yum -y install openssh-server vim sudo
# Add user
[root@CT105 ~]# adduser -G wheel nc
[root@CT105 ~]# passwd nc
# Enable passwordless sudo (welcome to non-production)
[root@CT105 ~]# visudo
# enable SSH
[root@CT105 ~]# systemctl enable sshd          
[root@CT105 ~]# systemctl start sshd   # so I can verify it works
# clean cache and tmp
[root@CT105 ~]# yum clean all
[root@CT105 ~]# rm -rf /var/cache/yum
[root@CT105 ~]# rm -rf /tmp/*

When you’re done, power it down;

[root@CT105 ~]# poweroff

Roll it back up

Powering off dumps you right back into the host cli, where you run:

root@gold:~# vzdump 105 --compress gzip --dumpdir /root/
root@gold:~# mv FILENAME.tar.gz /mnt/pve/gluster/template/cache/centos-7-ssh-20180908.tar.gz

Now you can spin up instances with your new template.