Spaces:
Runtime error
Runtime error
Alysha Creelman
commited on
Updating key_setup.sh with correct commands
Browse files- key_setup.sh +35 -67
key_setup.sh
CHANGED
|
@@ -5,99 +5,67 @@ MACHINE=paffenroth-23.dyn.wpi.edu
|
|
| 5 |
|
| 6 |
# Clean up from previous runs
|
| 7 |
ssh-keygen -f "/home/amcreelman/.ssh/known_hosts" -R "[${MACHINE}]:${PORT}
|
|
|
|
| 8 |
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
|
| 14 |
-
#
|
|
|
|
| 15 |
|
|
|
|
|
|
|
| 16 |
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
#
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
# open the authorized_keys file
|
| 24 |
-
less authorized_keys
|
| 25 |
-
|
| 26 |
-
# add our key to the authorized_keys file
|
| 27 |
-
cat my_key2.pub > authorized_keys
|
| 28 |
-
|
| 29 |
-
#change permissions on the keys
|
| 30 |
chmod 600 authorized_keys
|
| 31 |
|
| 32 |
echo "checking that the authorized_keys file is correct"
|
| 33 |
ls -l authorized_keys
|
| 34 |
cat authorized_keys
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
#NOTES FROM RANDY'S DEMO:
|
| 45 |
-
|
| 46 |
-
<<comment1 (this starts a block comment)
|
| 47 |
-
this block removes the old key (known-hosts) from the old machine
|
| 48 |
-
also it's called item potency and he thinks this should go at the botom (how this works without wiping the vm so we can't login I don't know)
|
| 49 |
-
ssh-keygen -f "/home/rcpaffenroth/.ssh/known_hosts" -R "[paffenroth-23.dyn.wpi.edu]:21003"
|
| 50 |
-
rm -rf tmp
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
constructing an authorized keys file locally and then checking it before copying it over
|
| 54 |
-
cat > says take this and erase it if it exists and then create it and add the file
|
| 55 |
-
cat >> says don't erase it just append this thing to it
|
| 56 |
-
the >> is for testing so that the other key will be in there and you don't brick your machine, but for the actual thing you want to use >
|
| 57 |
-
|
| 58 |
-
randy says we should put a pause in this, but I don't know how we check it if not just visually? and this is supposed to be automated?
|
| 59 |
-
he says put a "do you mean this you crazy person?"
|
| 60 |
-
echo "checking that the authorized_keys file is correct"
|
| 61 |
-
ls -l authorized_keys
|
| 62 |
-
cat authorized_keys
|
| 63 |
-
|
| 64 |
-
this line copies the authorized_keys file
|
| 65 |
-
he says it is not item potent and can't be rerun again?
|
| 66 |
scp -i student-admin_key -P ${PORT} -o StrictHostKeyChecking=no authorized_keys student-admin@${MACHINE}:~/.ssh/
|
| 67 |
|
| 68 |
-
ohhhhh so this block makes it so that you don't have to type the password for the key more than once
|
| 69 |
-
you type it once and it adds the key to a database, that's why we're adding the private key
|
| 70 |
# Add the key to the ssh-agent
|
| 71 |
eval "$(ssh-agent -s)"
|
| 72 |
ssh-add mykey
|
| 73 |
|
| 74 |
-
|
|
|
|
| 75 |
# Check the key file on the server
|
| 76 |
echo "checking that the authorized_keys file is correct"
|
| 77 |
ssh -p ${PORT} -o StrictHostKeyChecking=no student-admin@${MACHINE} "cat ~/.ssh/authorized_keys"
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
2. How does the password thing really work here? Same thing with the pause -
|
| 82 |
-
if it's supposed to be completely automated where if the server goes down at 2 am we can get it back up,
|
| 83 |
-
then doesn't this require human intervention to type in the password or approve the authorized_keys?
|
| 84 |
-
3. If we put the cleanup line at the end, it must just delete known_users, which is fine because we already know it works with that deleted?
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
comment1 (this ends the block comment)
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
|
|
|
|
|
|
| 101 |
|
|
|
|
| 102 |
|
|
|
|
|
|
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Clean up from previous runs
|
| 7 |
ssh-keygen -f "/home/amcreelman/.ssh/known_hosts" -R "[${MACHINE}]:${PORT}
|
| 8 |
+
rm -rf tmp2
|
| 9 |
|
| 10 |
+
# Create a temporary directory
|
| 11 |
+
mkdir tmp2
|
| 12 |
|
| 13 |
+
# copy the key to the temporary directory
|
| 14 |
+
cp wormington_keys/student-admin_key* tmp2
|
| 15 |
|
| 16 |
+
# copy the key to the temporary directory
|
| 17 |
+
cp wormington_keys/group_key* tmp2
|
| 18 |
|
| 19 |
+
# Change to the temporary directory
|
| 20 |
+
cd tmp2
|
| 21 |
|
| 22 |
+
# Set the permissions of the key
|
| 23 |
+
chmod 600 student-admin_key*
|
| 24 |
|
| 25 |
+
# Set the permissions of the key
|
| 26 |
+
chmod 600 group_key*
|
| 27 |
|
| 28 |
+
# skip creating unique key -- already have
|
| 29 |
|
| 30 |
+
# Insert the key into the authorized_keys file on the server
|
| 31 |
+
# One > creates
|
| 32 |
+
cat mykey.pub > authorized_keys
|
| 33 |
+
# two >> appends
|
| 34 |
+
# Remove to lock down machine
|
| 35 |
+
#cat student-admin_key.pub >> authorized_keys
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
chmod 600 authorized_keys
|
| 38 |
|
| 39 |
echo "checking that the authorized_keys file is correct"
|
| 40 |
ls -l authorized_keys
|
| 41 |
cat authorized_keys
|
| 42 |
|
| 43 |
+
# Copy the authorized_keys file to the server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
scp -i student-admin_key -P ${PORT} -o StrictHostKeyChecking=no authorized_keys student-admin@${MACHINE}:~/.ssh/
|
| 45 |
|
|
|
|
|
|
|
| 46 |
# Add the key to the ssh-agent
|
| 47 |
eval "$(ssh-agent -s)"
|
| 48 |
ssh-add mykey
|
| 49 |
|
| 50 |
+
# entered our password
|
| 51 |
+
|
| 52 |
# Check the key file on the server
|
| 53 |
echo "checking that the authorized_keys file is correct"
|
| 54 |
ssh -p ${PORT} -o StrictHostKeyChecking=no student-admin@${MACHINE} "cat ~/.ssh/authorized_keys"
|
| 55 |
|
| 56 |
+
# clone the repo
|
| 57 |
+
git clone https://github.com/alyshacreelman/Wormington-Scholar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
# Copy the files to the server
|
| 60 |
+
scp -P ${PORT} -o StrictHostKeyChecking=no -r Wormington-Scholar student-admin@${MACHINE}:~/
|
| 61 |
|
| 62 |
+
# from here on code is currently commented out in Randy's code
|
| 63 |
|
| 64 |
+
# check that the code in installed and start up the product
|
| 65 |
+
COMMAND="ssh -p ${PORT} -o StrictHostKeyChecking=no student-admin@${MACHINE}"
|
| 66 |
|
| 67 |
+
${COMMAND} "ls Wormington-Scholar"
|
| 68 |
+
${COMMAND} "sudo apt install -qq -y python3-venv"
|
| 69 |
+
${COMMAND} "cd Wormington-Scholar && python3 -m venv venv"
|
| 70 |
+
${COMMAND} "cd Wormington-Scholar && source venv/bin/activate && pip install -r requirements.txt"
|
| 71 |
+
${COMMAND} "nohup Wormington-Scholar/venv/bin/python3 Wormington-Scholar/app.py > log.txt 2>&1 &"
|