我试图设置一个ssh (Debian服务器和客户端都是)。
我更改了/etc/ssh/sshd_config (服务器):
PermitTunnel yes
PermitRootLogin without-password但是当我试图连接(客户机)时:
$ ssh -NTCf -vvvw 0:0 root@server-ip
...
debug1: Authentication succeeded (publickey).
Authenticated to <server-ip> ([<server-ip>]:22).
debug1: Requesting tun unit 0 in mode 1
debug1: sys_tun_open: failed to configure tunnel (mode 1): Operation not permitted
Tunnel device open failed.
Could not request tunnel forwarding.
...有什么不对的?请帮帮我!
我尝试将ssh作为root运行,但仍然存在错误(客户机):
# ssh -i ~user/.ssh/id_rsa -NTCf -vvvw any root@server-ip
....
debug1: Requesting tun unit 2147483647 in mode 1
debug1: sys_tun_open: tunnel mode 1 fd 5
Tunnel device open failed.
Could not request tunnel forwarding.
debug2: fd 3 setting TCP_NODELAY
...客户端配置:
OpenSSH_7.7p1 Debian-2, OpenSSL 1.0.2o 27 Mar 2018
Linux 4.16.0-2-amd64 #1 SMP Debian 4.16.12-1 (2018-05-27) x86_64
Debian GNU/Linux testing (buster)发布于 2018-06-29 19:00:45
创建网络接口需要根(或至少CAP_NET_ADMIN)权限。错误消息告诉客户端ssh命令无法创建tun0接口,运行客户端ssh时,这个strace摘录证实了这一点:
21510 open("/dev/net/tun", O_RDWR) = 4
21510 ioctl(4, TUNSETIFF, 0x7fff5f9f1530) = -1 EPERM (Operation not permitted)
21510 close(4) = 0
21510 write(2, "Tunnel device open failed.\r\n", 28) = 28
21510 write(2, "Could not request tunnel forward"..., 38) = 38最简单的方法是以根用户身份运行它,例如(配置和)使用sudo或su -c,并且可能使用-i提供正确的ssh键(或者它可以选择root的ssh键)。在Debian客户机上,这样做是可行的:
su -c 'ssh -i ~myuser/.ssh/id_rsa -NTCf -w 0:0 root@server-ip'您应该在测试时用-w 0:0替换-w any,以避免冲突。
另一种仍然需要根用户(或CAP_NET_ADMIN)的方法是按照常见的命名约定(在ssh参数后面重用的数字为X的tunX)预先创建接口,但赋予ssh用户对此接口的访问权限:
# ip tuntap add name tun0 mode tun user myuser
# ip address add 192.0.2.10/24 dev tun0
# ip link set dev tun0 up如果远程ssh用户不是root用户,也可以在远程服务器上(通过root)完成同样的操作。
ssh命令(以myuser的身份运行,例如:ssh -NTCf -w 0:0 remoteuser@server-ip)将能够使用具有匹配名称的预先存在的隧道接口来隧道通信量。
如果您在客户端没有任何特权,也不允许运行VM或具有服务器-ip网络访问权限的容器,则可能无法成功。
注意:在这个Q/A中,正如OP所发现的,在Debian (此时进行测试)中,包openssh和openssh-server版本1:7.7p1-2有一个防止使用tun/水龙头隧道的错误。修正Debian是从(Debian)版本1:7.7p1-3开始提供的.
https://unix.stackexchange.com/questions/452433
复制相似问题