HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: //proc/25618/root/lib64/systemd/scripts/sshd_checker.sh
#!/bin/sh
# Copyright (c) 2000-2020 Synology Inc. All rights reserved.

LOGGER="/usr/bin/logger"

# /var/empty must be owned by root and not group or world-writable.
check_empty_dir() {
	local privsep_path='/var/empty'

	if [ ! -d "${privsep_path}" ]; then
		/bin/mkdir -p -m755 "${privsep_path}"
	elif [ "$(stat -c %a ${privsep_path})" != "755" ]; then
		/bin/chmod 755 "${privsep_path}"
	fi
}

# It is required that your private key files are NOT accessible by others.
check_sshkey_perm() {
	local DEF_KEY_PERM='600'
	local DEF_PUB_KEY_PERM='644'
	local sshkey_prefix='/etc/ssh/ssh_host_'
	local ori_perm

	for sshkey in ${sshkey_prefix}*_key; do
		ori_perm="$(stat -c %a "${sshkey}")"
		if [ $? -eq 0 ] && [ "${ori_perm}" != "${DEF_KEY_PERM}" ]; then
			${LOGGER} -p warn "correct ${sshkey} permission from ${ori_perm} to ${DEF_KEY_PERM}"
			/bin/chmod "${DEF_KEY_PERM}" "${sshkey}"
		fi
	done
	for sshkey_pub in ${sshkey_prefix}*_key.pub; do
		ori_perm="$(stat -c %a "${sshkey_pub}")"
		if [ $? -eq 0 ] && [ "${ori_perm}" != "${DEF_PUB_KEY_PERM}" ]; then
			${LOGGER} -p warn "correct ${sshkey_pub} permission from ${ori_perm} to ${DEF_PUB_KEY_PERM}"
			/bin/chmod "${DEF_PUB_KEY_PERM}" "${sshkey_pub}"
		fi
	done
}

check_empty_dir
check_sshkey_perm