Last active
February 3, 2022 03:52
-
-
Save yeetyboi56-deprecated/50760048903815a74737ec2220ef2450 to your computer and use it in GitHub Desktop.
install my ssh key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# SHA256(id_ed25519.pub)= 9027bc32e05f04d3ad3b16062fa62e13d88b857a966ab102e2e3332a1e18013f | |
key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPqJNsgnhcAFAnBvjTljwkVnZGKXePZSZ22iYIJNjMO3 [email protected]" | |
echo "Assuming you are in the correct directory (~)" | |
# If user chose normal installation | |
if [ $1 == "install" ]; then | |
echo "The script will now create .ssh directory and install the key into .ssh/authorized_keys" | |
# Make directory | |
mkdir -p .ssh | |
# If key is already installed | |
if grep -q "$key" ".ssh/authorized_keys" -s ; then | |
echo "Key is already installed" | |
exit -1 | |
fi | |
# Install the key | |
echo "Installing the key in 5 seconds, SIGINT to abort..." | |
sleep 5 | |
echo "Installing..." | |
echo $key >> .ssh/authorized_keys | |
echo "Installed SSH key to .ssh/authorized_keys" | |
echo "Uninstall via the uninstall flag" | |
exit 0 | |
fi | |
# If user chose uninstall | |
if [ $1 == "uninstall" ]; then | |
# Make directory | |
mkdir -p .ssh | |
# If key is installed | |
if grep -q "$key" ".ssh/authorized_keys" -s ; then | |
echo "Uninstalling..." | |
sed -i '/[email protected]/d' .ssh/authorized_keys | |
exit 0 | |
fi | |
# If key is not installed | |
echo "Nothing to uninstall, please edit the .ssh/authorized_keys manually." | |
exit -1 | |
fi | |
echo "Invalid argument, valid arguments: install, uninstall" | |
exit -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment