Skip to main content

KT3 Upload website

Maak lijst met kandidaten in Excel, met alle studenten nummers en verzin wachtwoorden.

egrep "^$username" /etc/passwd >/dev/null

if [ $? -eq 0 ]; then
    echo "$username exists!"
    exit 1
else
    pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
    useradd -m -s /bin/bash -p $pass $username
    [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"

    # set home dir (www)
    usermod -d /var/www/softwaredeveloper/$username $username
    # set user in sftp group (which restricts access)
    usermod -g sftp $username
fi

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.

CREATE USER `u2080050`@`%` IDENTIFIED BY 'KLewdertje-501';
ALTER USER  `u2080050`@`%` REQUIRE NONE;
CREATE DATABASE IF NOT EXISTS `u2080050`;
GRANT ALL PRIVILEGES ON `u2080050`.* TO `u2080050`@`%`;

Bash script om dit te maken:

username=$1
password=$2

echo ""
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\`@\`%\`;"