Created
July 28, 2022 12:01
-
-
Save shawty/d37da7777bf20d2fe5e04527a25ac14a to your computer and use it in GitHub Desktop.
Provisioning Scripts that I use for managing containers running DOTNET 6 projects on LXD/LXC installs under Ubuntu server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ] | |
then | |
echo "User name must be provided on first parameter" | |
echo "USAGE: createuser.sh <username> <containername>" | |
exit 1 | |
fi | |
if [ -z "$2" ] | |
then | |
echo "Container name must be provided on second parameter" | |
echo "USAGE: createuser.sh <username> <containername>" | |
exit 1 | |
fi | |
lxc exec $2 -- adduser --disabled-password --gecos "" $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ] | |
then | |
echo "User name must be provided on first parameter" | |
echo "USAGE: createsshkey.sh <username> <containername>" | |
exit 1 | |
fi | |
if [ -z "$2" ] | |
then | |
echo "Container name must be provided on second parameter" | |
echo "USAGE: createsshkey.sh <username> <containername>" | |
exit 1 | |
fi | |
echo "Creating SSH keys for user $1 on container $2" | |
echo "" > empty | |
puttygen -t rsa -b 2048 -C "$1@$2" -q --old-passphrase empty -o $1-$2.ppk | |
puttygen -L $1-$2.ppk > $1-$2.pub | |
rm empty | |
echo "Adding keys to container" | |
lxc exec $2 -- mkdir /home/$1/.ssh | |
lxc file push $1-$2.pub $2/home/$1/.ssh/authorized_keys | |
lxc exec $2 -- chown $1:$1 /home/$1/.ssh | |
lxc exec $2 -- chown $1:$1 /home/$1/.ssh/authorized_keys | |
lxc exec $2 -- chmod 700 /home/$1/.ssh | |
lxc exec $2 -- chmod 600 /home/$1/.ssh/authorized_keys | |
rm $1-$2.pub | |
ipaddr=`lxc list -c4 --format csv $2 | cut -d' ' -f1` | |
echo "DONE! - Please copy $1-$2.ppk to your windows machine," | |
echo "store it in a safe place," | |
echo "then add it to a putty profile to login to container" | |
echo " '$2' at '$ipaddr'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ] | |
then | |
echo "User name must be provided on first parameter" | |
echo "USAGE: createuser.sh <username> <containername>" | |
exit 1 | |
fi | |
if [ -z "$2" ] | |
then | |
echo "Container name must be provided on second parameter" | |
echo "USAGE: createuser.sh <username> <containername>" | |
exit 1 | |
fi | |
lxc exec $2 -- deluser --remove-home $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment