Add message if key was alrady added or removed

This commit is contained in:
Clemens Schwaighofer
2024-08-30 11:43:41 +09:00
parent 2a34399e61
commit 068131e32d
5 changed files with 10 additions and 2 deletions

View File

@@ -99,6 +99,8 @@ remove_ssh_key() {
sed -i "/${pub_key_escaped}/d" "${AUTH_KEY_FILE}";
${RMV_CHMOD_UW} "${AUTH_KEY_FILE}";
${ADD_CHATTR_I} "${AUTH_KEY_FILE}";
else
echo "[!] Already removed";
fi;
EOF
);

View File

@@ -163,6 +163,8 @@ add_ssh_key() {
echo "${pub_key_write}" >> "${AUTH_KEY_FILE}" || exit 1;
${RMV_CHMOD_UW} "${AUTH_KEY_FILE}";
${ADD_CHATTR_I} "${AUTH_KEY_FILE}";
else
echo "[!] Already added";
fi;
EOF
);

4
bin/user-add-ssh-key.sh Normal file → Executable file
View File

@@ -127,6 +127,8 @@ add_ssh_key() {
echo "${pub_key_write}" >> "${AUTH_KEY_FILE}" || exit 1;
${RMV_CHMOD_UW} "${AUTH_KEY_FILE}";
${ADD_CHATTR_I} "${AUTH_KEY_FILE}";
else
echo "[!] Already added";
fi;
EOF
);
@@ -171,7 +173,7 @@ while read -r line; do
continue;
fi
echo "[+] Add new public key '${SSH_KEY_PUB_FILE}' to: ${username}@${hostname}";
echo "[+] Add new public key '${USER_PUBLIC_KEY}' to: ${username}@${hostname}";
# flags: (not used at the moment)
# Possible: U (add to .ssh/authorized_keys)

4
bin/user-remove-ssh-key.sh Normal file → Executable file
View File

@@ -109,6 +109,8 @@ remove_ssh_key() {
sed -i "/${pub_key_escaped}/d" "${AUTH_KEY_FILE}";
${RMV_CHMOD_UW} "${AUTH_KEY_FILE}";
${ADD_CHATTR_I} "${AUTH_KEY_FILE}";
else
echo "[!] Already removed";
fi;
EOF
);
@@ -147,7 +149,7 @@ while read -r line; do
continue;
fi
echo "[-] Remove public key '${SSH_KEY_PUB_FILE}' from: ${username}@${hostname}";
echo "[-] Remove public key '${USER_PUBLIC_KEY}' from: ${username}@${hostname}";
uninstall_ssh_key "${hostname}" "${username}" "${SSH_KEY_PUB_FILE}" "/etc/ssh/authorized_keys/${username}"