我正在开发MIPSEL ci20开发板。它运行Debian 7,因此不再接收安全更新。Debian 8处于beta版,它似乎遇到了一些内存问题,因此我不想在此刻冒险进行升级。
我已经将OpenSSL更新到1.0.2h(从1.0.1e开始),并将OpenSSH更新到7.3(从6.0开始)。我还使用OpenSSL与OpenSSH进行静态链接,以避免在配置过程中库版本检查遇到的问题。
我在查找有关指示Debian使用本地OpenSSH的信息时遇到麻烦。我发现的信息始于apt-get install openssh-server
。例如,Debian Wiki和服务器安装假定Debian提供了OpenSSH。
收看/etc
for会sshd
显示很多硬编码的路径,例如:
$ sudo grep -R 'sshd' /etc 2>/dev/null
...
/etc/network/if-up.d/openssh-server:if [ ! -e /usr/sbin/sshd ]; then
/etc/init.d/ssh:test -x /usr/sbin/sshd || exit 0
/etc/init.d/ssh: if start-stop-daemon ... --exec /usr/sbin/sshd -- $SSHD_OPTS; then
...
我如何告诉Debian在使用OpenSSH服务器/usr/local/sbin/sshd
?
可以使用本地OpenSSH服务器,包括完全删除发行版OpenSSH服务器。共有四个步骤。
构建并安装OpenSSH服务器
第一步是构建适合您口味的OpenSSH版本。在为OS X构建OpenSSH时给出了OS X的示例。。它也主要适用于Linux,并使用静态链接(请参阅参考资料sed
)来避免配置和动态链接问题。
删除发行版OpenSSH服务器
第二步是执行apt-get remove --purge openssh-server
。在--purge
试图确保无交叉授粉。
如果需要,请备份当前电流sshd_config
以供将来参考。请注意,OpenSSL 1.0.2和OpenSSH 7.3提供了其前任产品所没有的功能,例如curve25519。
创建一个非特权用户
第三步是创建一个非特权用户以进行特权分离。这是必需的,因为先前的非特权用户帐户已清除。对于此步骤,请参见README.privsep
:
# mkdir /var/empty
# chown root:sys /var/empty
# chmod 755 /var/empty
# groupadd sshd
# useradd -g sshd -c 'sshd privsep' -d /var/empty -s /bin/false sshd
为sshd-local添加启动脚本
有关此步骤,请参阅管理员手册中的使脚本在Debian启动时运行。以下脚本基于Debian的SSH启动脚本。名称已更改sshd-local
以避免冲突。它还可以-f /usr/local/etc/sshd_config
确保使用正确的配置文件。
#! /bin/sh
### BEGIN INIT INFO
# Provides: sshd-local
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Local OpenBSD Secure Shell server
### END INIT INFO
set -e
# /etc/init.d/ssh-local: start and stop the local OpenBSD secure shell daemon
test -x /usr/local/sbin/sshd || exit 0
( /usr/local/sbin/sshd -\? 2>&1 | grep -q OpenSSH ) 2>/dev/null || exit 0
umask 022
if test -f /etc/default/ssh; then
. /etc/default/ssh
fi
if test -f /lib/lsb/init-functions; then
. /lib/lsb/init-functions
fi
if [ -n "$2" ]; then
SSHD_OPTS="$SSHD_OPTS -f /usr/local/etc/sshd_config $2"
fi
# Are we running from init?
run_by_init() {
([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
}
check_for_no_start() {
# forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists
if [ -e /etc/ssh/sshd_not_to_be_run ]; then
if [ "$1" = log_end_msg ]; then
log_end_msg 0 || true
fi
if ! run_by_init; then
log_action_msg "Local OpenBSD Secure Shell server not in use (/etc/ssh/sshd_not_to_be_run)" || true
fi
exit 0
fi
}
check_dev_null() {
if [ ! -c /dev/null ]; then
if [ "$1" = log_end_msg ]; then
log_end_msg 1 || true
fi
if ! run_by_init; then
log_action_msg "/dev/null is not a character device!" || true
fi
exit 1
fi
}
check_privsep_dir() {
# Create the PrivSep empty dir if necessary
if [ ! -d /var/run/sshd-local ]; then
mkdir /var/run/sshd-local
chmod 0755 /var/run/sshd-local
fi
}
check_config() {
if [ ! -e /etc/ssh/sshd_not_to_be_run ]; then
/usr/local/sbin/sshd $SSHD_OPTS -t || exit 1
fi
}
export PATH="${PATH:+$PATH:}/usr/local/sbin:/usr/sbin:/sbin"
case "$1" in
start)
check_privsep_dir
check_for_no_start
check_dev_null
log_daemon_msg "Starting local OpenBSD Secure Shell server" "sshd" || true
if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd-local.pid --exec /usr/local/sbin/sshd -- $SSHD_OPTS; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
stop)
log_daemon_msg "Stopping local OpenBSD Secure Shell server" "sshd" || true
if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd-local.pid; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
reload|force-reload)
check_for_no_start
check_config
log_daemon_msg "Reloading local OpenBSD Secure Shell server's configuration" "sshd" || true
if start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd-local.pid --exec /usr/local/sbin/sshd; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
restart)
check_privsep_dir
check_config
log_daemon_msg "Restarting local OpenBSD Secure Shell server" "sshd" || true
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd-local.pid
check_for_no_start log_end_msg
check_dev_null log_end_msg
if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd-local.pid --exec /usr/local/sbin/sshd -- $SSHD_OPTS; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
try-restart)
check_privsep_dir
check_config
log_daemon_msg "Restarting local OpenBSD Secure Shell server" "sshd" || true
RET=0
start-stop-daemon --stop --quiet --retry 30 --pidfile /var/run/sshd-local.pid || RET="$?"
case $RET in
0)
# old daemon stopped
check_for_no_start log_end_msg
check_dev_null log_end_msg
if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd-local.pid --exec /usr/local/sbin/sshd -- $SSHD_OPTS; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
1)
# daemon not running
log_progress_msg "(not running)" || true
log_end_msg 0 || true
;;
*)
# failed to stop
log_progress_msg "(failed to stop)" || true
log_end_msg 1 || true
;;
esac
;;
status)
status_of_proc -p /var/run/sshd-local.pid /usr/local/sbin/sshd sshd && exit 0 || exit $?
;;
*)
log_action_msg "Usage: /etc/init.d/ssh-local {start|stop|reload|force-reload|restart|try-restart|status}" || true
exit 1
esac
exit 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句