Spaces:
Runtime error
Runtime error
Jennifer Kimball
commited on
Update key_setup.sh - adding comments from Randy's demo
Browse files- key_setup.sh +81 -3
key_setup.sh
CHANGED
|
@@ -3,14 +3,25 @@
|
|
| 3 |
PORT=22003
|
| 4 |
MACHINE=paffenroth-23.dyn.wpi.edu
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# login using student-admin key
|
| 7 |
-
ssh -i student_admin -p {PORT} student-admin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# move directories
|
| 10 |
-
cd .ssh
|
| 11 |
|
| 12 |
# open the authorized_keys file
|
| 13 |
-
|
| 14 |
|
| 15 |
# add our key to the authorized_keys file
|
| 16 |
cat my_key2.pub > authorized_keys
|
|
@@ -23,3 +34,70 @@ ls -l authorized_keys
|
|
| 23 |
cat authorized_keys
|
| 24 |
|
| 25 |
#WANT TO PUT A CHECK ON THE PERMISSIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
PORT=22003
|
| 4 |
MACHINE=paffenroth-23.dyn.wpi.edu
|
| 5 |
|
| 6 |
+
# Clean up from previous runs
|
| 7 |
+
# ssh-keygen -f "/home/rcpaffenroth/.ssh/known_hosts" -R "[${MACHINE}]:${PORT}
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
# login using student-admin key
|
| 12 |
+
ssh -i student_admin -p ${PORT} student-admin@${MACHINE}
|
| 13 |
+
|
| 14 |
+
#copy the key to the tmp directory
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#possibly have to rm known_hosts in ssh at some point to prevent an error
|
| 19 |
|
| 20 |
# move directories
|
| 21 |
+
#cd .ssh
|
| 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
|
|
|
|
| 34 |
cat authorized_keys
|
| 35 |
|
| 36 |
#WANT TO PUT A CHECK ON THE PERMISSIONS
|
| 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 |
+
he says this is dumb because it only checks it if it's right
|
| 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 |
+
Remaining Questions:
|
| 80 |
+
1. Why does he bother copying over the student-admin key to the new directory and changing the permissions?
|
| 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 |
+
|