Skip to content

Instantly share code, notes, and snippets.

@tinoji
Created February 7, 2018 01:02
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save tinoji/7e066d61a84d98374b08d2414d9524f2 to your computer and use it in GitHub Desktop.
Save tinoji/7e066d61a84d98374b08d2414d9524f2 to your computer and use it in GitHub Desktop.
Create and provision Proxmox LXC by pct command
pct create <id> /var/lib/vz/template/cache/centos-7-default_20170504_amd64.tar.xz \
-arch amd64 \
-ostype <centos|ubuntu|etc> \
-hostname <hostname> \
-cores <cores> \
-memory <memory(MB)> \
-swap <swap(MB)> \
-storage local-lvm \
-password \
-net0 name=eth0,bridge=<bridge>,gw=<gateway>,ip=<cidr>,type=veth &&\
pct start <id> &&\
sleep 10 &&\
pct resize <id> rootfs <storage(ex: +4G)> &&\
pct exec <id> -- bash -c "yum update -y &&\
yum install -y openssh-server &&\
systemctl start sshd &&\
useradd -mU hogeuser &&\
echo "password" | passwd --stdin hogeuser"
@battaglin
Copy link

Thnx.. this is awesome..

@maestrow
Copy link

thanks

@jjromannet
Copy link

jjromannet commented Apr 13, 2022

Here is my example using DHCP and defining volume size, my storage name is main

pct create <id> /data/template/cache/debian-11-standard_11.3-1_amd64.tar.zst \
 -ostype <debian|centos|etc> \ \
 -hostname <hostname> \
 -cores <cores>  \
 -memory <memory(MB)> \
 -swap <swap(MB)> \
 -rootfs volume=main:<sizeInGB> \
 -net0 name=eth0,bridge=<bridge>,ip=dhcp,hwaddr=<macaddr format 00:00:00:00:00:00>

pct start <id>
pct exec <id> -- mkdir -p /root/.ssh/
pct push <id> ~/.ssh/authorized_keys /root/.ssh/authorized_keys

@belov38
Copy link

belov38 commented Oct 22, 2023

You can use a param -ssh-public-keys to push your keys during creating

# pct help create
...
  -ssh-public-keys <filepath>
             Setup public SSH keys (one key per line, OpenSSH format).
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment