KT3 Upload website
Maak lijst met kandidaten in Excel, met alle studenten nummers en verzin wachtwoorden.
egrepMaak "^$username"een /etc/passwdtext >/dev/nullinput iffile [met $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -userid's /bin/bashen -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
# set home dirpasswords (www)gescheiden usermoddoor -dspatie).
/var/www/softwaredeveloper/$usernameScipts $usernameran #on setUbuntu userServer in sftp group (which restricts access)
usermod -g sftp $username
fi
VPS
SFTP restriction in /etc/ssh/sshd_config (aan eind toevoegen)
Match Group sftp
ForceCommand internal-sftp
ChrootDirectory %h
AllowTCPForwarding no
PermitTunnel no
X11Forwarding no
SQL, create uer u<nummer> en maak db u<nummer> en geef user alle rechten.Readme
CREATEinput USERfile `u2080050`@`%`consists IDENTIFIEDout BYof 'KLewdertje-501';line ALTERwith
USER<userid> `u2080050`@`%`<password>
REQUIREadd NONE;users
CREATErun DATABASEaddUser.sh IF<file>
NOTrun EXISTScreatDBUsers.sql `u2080050`;file; GRANTsudo ALLmysql PRIVILEGES< ONcreateDB `u2080050`.*Users.sql
TOremove
`u2080050`@`%`;
run BashremoveUser.sf script<file>
omgo ditto tephp maken:
username=$1and password=$2delete echodabases ""and echo "CREATE USER \`$username\`@\`%\` IDENTIFIED BY '$password';"
echo "ALTER USER \`$username\`@\`%\` REQUIRE NONE;";
echo "CREATE DATABASE IF NOT EXISTS \`$username\`;";
echo "GRANT ALL PRIVILEGES ON \`$username\`.* TO \`$username\`@\`%\`;"users
Script add users
#!/bin/bash
# Script to add a user to Linux system
# Params <user> <passw> or <file>
DB_FILE=createDBUsers.sql
addThisUser() {
if [ $(id -u) -eq 0 ]; then
echo "" >> $DB_FILE
if [ "$1" == "" ]; then
read -p "Enter username : " username
else
username=$1
fi
if [ "$2" == "" ]; then
read -s -p "Enter password : " password
else
password=$2
fi
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
U_HOME=/var/www/softwaredeveloper/$username
U_GROUP=sftp
U_SHELL=/bin/bash
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -d $U_HOME -g $U_GROUP -m -s $U_SHELL -p $pass $username
[ $? -eq 0 ] && echo "User $username has been added to system!" || echo "Failed to add a user!"
chown $username $U_HOME
echo "<?php echo \"welkom $username\"; ?>" > $U_HOME/index.php
chown $username $U_HOME/index.php
echo "" >> $DB_FILE
echo "CREATE USER \`$username\`@\`%\` IDENTIFIED BY '$password';" >> $DB_FILE
echo "ALTER USER \`$username\`@\`%\` REQUIRE NONE;" >> $DB_FILE
echo "CREATE DATABASE IF NOT EXISTS \`$username\`;" >> $DB_FILE
echo "GRANT ALL PRIVILEGES ON \`$username\`.* TO \`$username\`@\`%\`;" >> $DB_FILE
fi
else
echo "Only root may add a user to the system"
exit 2
fi
}
# is parameter is file then read input from file <user> Mpassword>
# else read two command line params
if test -f "$1"; then
while IFS= read -r line
do
addThisUser $line
done < $1
else
addThisUser $1 $2
fi
script del users
#!/bin/bash
# remove user, params <user> or <file>
removeThisUser() {
if [ $(id -u) -ne 0 ]; then
echo "Only root may add a user to the system"
exit 2
fi
if [ "$1" == "" ]; then
read -p "Enter username : " username
else
username=$1
fi
if [ $? -eq 0 ]; then
userdel -r $username
getent group $username || groupadd $username
U_HOME=/var/www/softwaredeveloper/$username
echo "Remove $U_HOME"
fi
}
# is parameter is file then read input from file <user>
# else read command line params
if test -f "$1"; then
while IFS= read -r line
do
removeThisUser $line
done < $1
else
removeThisUser $1 $2
fi