-
Notifications
You must be signed in to change notification settings - Fork 1
#107_Script_To_Setup_Users_And_SSH
Andrew edited this page May 1, 2019
·
1 revision
Andrew Davis
1/5/19
I have taken the SSH keys from GDrive and put them on my opax hosting. I also have a script to pull down those keys, add users and add the keys on an Ubuntu system.
The link to the script is: http://opax.swin.edu.au/~101301597/capstone/setup.sh
The link to the key tarball is: http://opax.swin.edu.au/~101301597/capstone/pubkeys.tar
Everyone's username is their first name in lowercase eg: andrew paul ahmad nhi shane
Steps to use
- Download the script
- Examine the script for best practice security behavior
- Make the script executeable
- Elevate to root user
- Execute script
- Drop privilege
- Logoff then test if you can login under your username Run these commands
$curl http://opax.swin.edu.au/~101301597/capstone/setup.sh -o setup.sh
$cat setup.sh
$chmod +x setup.sh
$sudo su
$./setup.sh
$exit
Steps:
- ssh to the server IP address using your username
- set a new password using passwd, you will be prompted to enter it twice
- test sudo works with your new password with sudo -v. If it works correctly there will be no output
$ssh NAME@serveraddress
$passwd
$sudo -v
#!/bin/bash
#get public keys
curl http://opax.swin.edu.au/~101301597/capstone/pubkeys.tar -o pubkeys.tar
#if the pubkeys can't be pulled down then exit
if [ ! -f "./pubkeys.tar" ]; then echo error downloading keys; exit; fi
tar -xf pubkeys.tar
#All our names
names=( "andrew" "shane" "paul" "nhi" "ahmad")
for n in ${names[@]}; do
#create user and add to sudoers
adduser $n --gecos "$n,RoomNumber,WorkPhone,HomePhone" --disabled-password
#change from disabled password to blank password
passwd $n -d
usermod -aG sudo $n
#before we can add keys we need to create the ~/.ssh/authorized_keys file
mkdir /home/$n/.ssh
touch /home/$n/.ssh/authorized_keys
#And make it owned by the user
chown -R $n:$n /home/$n
#conviniently all the public key names are the same as the names in the array suffixed with .pub
cat $n.pub >> /home/$n/.ssh/authorized_keys
rm $n.pub
done
rm pubkeys.tar
About
Documents
-
AWS
-
Other
-
REST
-
Nectar
-
Rancher
-
ASP.NET
-
Data
-
Blockchains
-
Processes