v-delete-user-ssh-key 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # info: add ssh key
  3. # options: USER key
  4. #
  5. # Function check if $user/.ssh/authorized_keys exists and create it
  6. # After that it append the new key(s)
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument definition
  11. user=$1
  12. keyid=$2
  13. # Includes
  14. source $HESTIA/func/main.sh
  15. source $HESTIA/conf/hestia.conf
  16. # Additional argument formatting
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. is_format_valid 'user'
  21. is_object_valid 'user' 'USER' "$user"
  22. is_object_unsuspended 'user' 'USER' "$user"
  23. source $USER_DATA/user.conf
  24. FILE=$HOMEDIR/$user/.ssh/authorized_keys
  25. if [ ! -f "$FILE" ]; then
  26. exit;
  27. fi
  28. # Perform verification if read-only mode is enabled
  29. check_hestia_demo_mode
  30. #----------------------------------------------------------#
  31. # Action #
  32. #----------------------------------------------------------#
  33. sed -i "/${keyid}/d" "$FILE"
  34. #----------------------------------------------------------#
  35. # Hestia #
  36. #----------------------------------------------------------#
  37. # Logging
  38. log_history "DELETE ssh-key $user"
  39. log_event "$OK" "$ARGUMENTS"
  40. exit