我的目标是sshd
使用我自己的配置文件在非特权端口(例如 2222)上启动第二个实例。
显然,该sshd
进程不能setuid
以运行sshd
守护程序的用户以外的用户身份登录,这显然是不可能的。
但是,是否有可能有一个工作sshd
守护程序适用于当前正在运行的用户?对于我的用例,这很好。
我尝试sshd
使用我自己的配置文件和主机密钥启动一个实例,然后sshd
进程启动(没有关于不是 root 的抱怨,就像某些命令一样),但是当我尝试连接到该端口时,sshd
进程终止了。
$ /usr/sbin/sshd -dD -h .ssh/id_rsa -p 2222
debug1: sshd version OpenSSH_5.6p1
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: setgroups() failed: Operation not permitted
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-dD'
debug1: rexec_argv[2]='-h'
debug1: rexec_argv[3]='.ssh/id_rsa'
debug1: rexec_argv[4]='-p'
debug1: rexec_argv[5]='2222'
debug1: Bind to port 2222 on 0.0.0.0.
Server listening on 0.0.0.0 port 2222.
debug1: Bind to port 2222 on ::.
Server listening on :: port 2222.
debug1: fd 6 clearing O_NONBLOCK
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 6 out 6 newsock 6 pipe -1 sock 9
debug1: inetd sockets after dupping: 5, 5
Connection from ::1 port 57670
debug1: Client protocol version 2.0; client software version OpenSSH_5.6
debug1: match: OpenSSH_5.6 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug1: list_hostkey_types:
No supported key exchange algorithms
debug1: do_cleanup
debug1: do_cleanup
debug1: audit_event: unhandled event 12
Run Code Online (Sandbox Code Playgroud)
这debug1: setgroups() failed: Operation not permitted
条线显然很突出,但直到它尝试接受连接才会终止。
Bo *_*nes 46
经过一番挖掘,我想通了。
从您创建的新文件的sshd -f ~/.ssh/sshd_config
位置开始该过程/.ssh/sshd_config
。在其他选项(例如不同的主机密钥、不同的端口等)中,您需要添加行UsePrivilegeSeparation no
. 这将阻止sshd
进程尝试执行任何setuid
或setgid
调用,并允许它以您的用户身份继续运行并以您的用户身份接受连接。
编辑:在弄清楚之后,其他人向我发送了此链接,这证实这是正确的方法:http : //cygwin.com/ml/cygwin/2008-04/msg00363.html
小智 11
作为对该线程的更新,版本 7.5 中的 OpenSSH 弃用了 UsePrivilegeSeparation 选项,因此无法禁用权限分离。现在似乎不可能以用户身份运行 SSHD。
见https://www.openssh.com/releasenotes.html
这是一个基于 Bo Jeanes 回答的 userland bash sript:
mkdir ${HOME}/custom_ssh
ssh-keygen -f ${HOME}/custom_ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f ${HOME}/custom_ssh/ssh_host_dsa_key -N '' -t dsa
echo "Port 2222
HostKey ${HOME}/custom_ssh/ssh_host_rsa_key
HostKey ${HOME}/custom_ssh/ssh_host_dsa_key
AuthorizedKeysFile .ssh/authorized_keys
ChallengeResponseAuthentication no
UsePAM yes
Subsystem sftp /usr/lib/ssh/sftp-server
PidFile ${HOME}/custom_ssh/sshd.pid" > ${HOME}/custom_ssh/sshd_config
/usr/bin/sshd -f ${HOME}/custom_ssh/sshd_config
echo "
--------
Process ID : ${HOME}/custom_ssh/sshd.pid
-------"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
33645 次 |
最近记录: |