在/ usr / local / sbin / sshd使用SSH服务器?

w

我正在开发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。

收看/etcfor会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

w

可以使用本地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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Dockerfile中运行/ usr / sbin / sshd不起作用

`brew link unbound`返回`/ usr / local / sbin is not writable'错误

'echo user:pass | / usr / sbin / chpasswd'覆盖root密码?

ssh找不到/ usr / local / bin路径

Auditbeat排除/ usr / sbin / cron

在/ usr / local / lib中使用共享库

如何通过DASH在/ usr / sbin中搜索程序

/ usr / sbin,/ usr / local / sbin和/ usr / local / bin的含义是什么?

/ bin,/ sbin,/ usr / bin,/ usr / sbin,/ usr / local / bin,/ usr / local / sbin之间的差异

意外重命名了“ / usr / sbin”中的文件

使用distutils将脚本链接安装到/ usr / local / sbin

我有理由不将/ usr / local / sbin,/ usr / sbin,/ sbin添加到Debian上的路径中吗?

为什么logrotate的bin路径是`/ usr / sbin`

macOS Sierra 10.12.2根无法写入/ usr / sbin

共享的/ usr或/ usr / local目录

node.js冲突:/ sbin / node与/ usr / bin / node

sudo:/usr/sbin/mkfs.ext4:找不到命令

联机服务器上的/ usr / local / lib在哪里

NFS状态:execstartpre = / usr / sbin / exportfs -r错误

使用/ usr / local / bin / mpd代替/ usr / bin / mpd

-bash:/ usr / sbin / mail:没有这样的文件或目录

如何从/ usr / local强制使用OpenSSL

apt-get上的错误:/ usr / sbin / update-info-dir:23:/ etc / environment:/usr/local/lib/python2.7/dist-packages:权限被拒绝

echo $ PATH结果在/ usr / local / bin:/ usr / bin:/ bin:/ usr / sbin:/ sbin:/ bin:/ bin:/ bin:/ bin:/ bin:

{/ bin,/ lib,/ sbin}是否在Ubuntu中符号链接到/ usr?

为什么我得到“ /sbin/ldconfig.real:/usr/local/cuda/lib64/libcudnn.so.7不是符号链接”?

Cygwin安装:缺少/ usr / bin和/ usr / local / sbin目录

/usr/sbin/nologin 有什么副作用吗?

在没有 /usr/local/bin/composer 的服务器上使用 EasyDeployBundle 托管 Symfony 4 应用程序