-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiocage_jail_build.sh
66 lines (51 loc) · 2.21 KB
/
iocage_jail_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
# Set variables for jail name and IP address
JAIL_NAME="jail_name"
JAIL_IP="xxx.xxx.xxx.xxx"
JAIL_NETMASK="xx"
DOMAIN_NAME="example.com"
INTERFACE="eth0" #Check your interface name
ROOTPASS="root_password"
# Create a temporary JSON file for package installation
echo '{"pkgs":["nano","wget","bash","curl","sudo","p5-Net-Nslookup", "openssh-portable"]}' > /tmp/pkg.json
# Create the iocage jail
iocage create -b -n "${JAIL_NAME}" -p /tmp/pkg.json -r 13.2-RELEASE \
dhcp=0 \
vnet=1 \
bpf=1 \
ip4_addr="vnet0|${JAIL_IP}/${JAIL_NETMASK}" \
defaultrouter="auto" \
defaultrouter6=none \
ip6_saddrsel=0 \
resolver="none" \
host_domainname="${DOMAIN_NAME}" \
boot=1 \
vnet_default_interface="${INTERFACE}" \
allow_mlock=1
# Remove the temporary JSON file
rm /tmp/pkg.json
# Set allow_mlock for the jail
iocage set allow_mlock=1 "${JAIL_NAME}"
# Set bash as the default shell for root user in the jail
iocage exec "${JAIL_NAME}" chsh -s /usr/local/bin/bash root
# Create .bashrc file for root user
iocage exec "${JAIL_NAME}" touch /root/.bashrc
# Add custom prompt to .bashrc
# iocage exec "${JAIL_NAME}" echo "export PS1='[\u@\h \W]\\$ '" >> /root/.bashrc
# Set the default shell for new users to bash
iocage exec "${JAIL_NAME}" echo 'shell="/usr/local/bin/bash"' >> /etc/rc.conf
# Enable SSH in the jail
# Comment out if you do not need SSH set up by default
iocage exec "${JAIL_NAME}" sysrc sshd_enable="YES"
# Configure SSH to allow password authentication
# Comment out if you do not need SSH set up by default
iocage exec "${JAIL_NAME}" sed -i '' 's/^#PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
iocage exec "${JAIL_NAME}" sed -i '' 's/^#PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config
# Set a password for the root user (replace 'your_password' with the desired password)
iocage exec "${JAIL_NAME}" pw usermod root -h 0 <<EOF
${ROOTPASS}
EOF
# Start the SSH service
# Comment out if you do not need SSH set up by default
iocage exec "${JAIL_NAME}" service sshd start
echo "Jail '${JAIL_NAME}' created with IP ${JAIL_IP}/${JAIL_NETMASK} and SSH enabled with password authentication"