moved helpers separately
This commit is contained in:
+3
-32
@@ -36,34 +36,9 @@
|
||||
|
||||
load_conf "ssh"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Internal helper: remove <key> (a name or an IP, in known_hosts notation, so
|
||||
# also "[host]:port") from the known_hosts file <file> with ssh-keygen -R.
|
||||
# ssh-keygen writes a new file: run by root on another user's file (--all-users)
|
||||
# it would leave it owned by root with mode 0644, which keeps that user's ssh
|
||||
# from adding host keys, or exposes a private file. The owner and mode of the
|
||||
# file, and of its ".old" backup, are therefore put back.
|
||||
# Returns ssh-keygen's status (non-zero when the key was not found).
|
||||
# Usage: _rmhost_remove <key> <file>
|
||||
_rmhost_remove()
|
||||
{
|
||||
local key="$1" file="$2" owner="" mode="" rc=0
|
||||
if [[ ${EUID:-$(id -u)} -eq 0 ]]; then
|
||||
owner=$(stat -c '%u:%g' -- "$file" 2>/dev/null)
|
||||
mode=$(stat -c '%a' -- "$file" 2>/dev/null)
|
||||
fi
|
||||
|
||||
ssh-keygen -R "$key" -f "$file" </dev/null >/dev/null 2>&1 || rc=$?
|
||||
|
||||
if [[ -n $owner && -n $mode ]]; then
|
||||
chown "$owner" -- "$file" "${file}.old" 2>/dev/null
|
||||
chmod "$mode" -- "$file" "${file}.old" 2>/dev/null
|
||||
fi
|
||||
return "$rc"
|
||||
}
|
||||
export -f _rmhost_remove
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Common helpers, then the ones private to this module (helpers/ssh.sh)
|
||||
declare -F _profile_load_helpers >/dev/null || . "$(dirname -- "${BASH_SOURCE[0]}")/../helpers/common.sh"
|
||||
_profile_load_helpers "${BASH_SOURCE[0]}"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Remove host entries (name and IP) from ~/.ssh/known_hosts for the active user
|
||||
@@ -252,9 +227,6 @@ rmhost()
|
||||
done
|
||||
}
|
||||
export -f rmhost
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Login root via SSH on the given machine
|
||||
# Usage: ssr <server [ssh options]>
|
||||
@@ -311,5 +283,4 @@ ssr()
|
||||
export -f ssr
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# EOF
|
||||
|
||||
Reference in New Issue
Block a user