975779964
V2EX  ›  Linux

windows 远程 archlinux + i3wm 最佳实践?

By 975779964 at 2022 年 7 月 22 日 · 7946 次点击

背景

公司不让用虚拟机,要用 windows + 安全管理软件 ,但可以 申请 远程 虚拟机环境 ,我平时都是用 i3wm+ archlinux 开发 ,i3wm 切换程序 窗口很方便 ,所以想到 用 本机 win+ 远程 虚拟机 archlinux 的 开发模式

常用软件

alacritty , xkeysnail , webstorm , goland ,chrome 等等

xkeysnail 是用来映射按键的 ,好让我盲打 编程中常用的符号,现在 已经离不开了,具体可以看 V2EX 如何打符号的帖子

i3wm 配置

i3wm 基本没有配置 就配置了 个 i3 status bar ,改了 快捷键 也没有装 sddm 登录软件 ,目前 arch 的启动流程是

  1. 开机
  2. 进入命令行页面 ,输入 startx ,进入 i3wm 桌面环境
  3. 启动 alacritty ,chrome 等软件 ,在 alacritty 中 启动 xkeysnail 使用 自定义的 按键 映射 来快速打符号

远程软件安装

安装 了 xrdp tigervnc 两个软件 ,然后 启动 xrdp 服务

在 windows 下 打开 mstsc , 输入 linux 的 ip , 会进入一个 蓝色 的背景页面

会有 session , username ,和 password 三个 表格 字段

session 有 xorg , xvnc ,vnc-any , neutrinordp-any 4 个选项

其中 使用 xorg 选项 输入 用户名密码后 , 就还是一样的蓝背景 ,过一会 说 连接拒绝之类的 ,无法 远程

选择 xvnc 选项,输入用户名密码后, 可以 进 远程 的 i3wm 桌面

选择 vnc-any 和 neutrinordp-any 后 ,都提示要 输入 ip port 和 密码 ,但是我看 对应的端口号 我应该是没有起来 ,所以 输入了 也是黑屏 ,这两个方法 先放弃

使用 xvnc 的方式 远程连接 i3wm 遇到的问题

使用 xvnc 方式 远程连接 i3wm 后 ,正常的 webstorm , chrome 软件 都能打开 ,但是 alacritty 却打不开了 ,还好我还有别的 terminal 备用 , 我打开 了 cool-retro-term 终端 然后输入 alacritty

报错为

$ alacritty
thread 'main' panicked at 'Failed to initialize any backend! Wayland status: NoCompositorListening X11 status: XOpenDisplayFailed', /build/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/mod.rs:619:9 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

然后 我又尝试启动 xkeysnail 按键 映射软件 ,也无法打开 ,报错为

Traceback (most recent call last): [8/4707] File "/usr/lib/python3.10/site-packages/Xlib/support/unix_connect.py", line 119, in get_socket
s = _get_unix_socket(address)
File "/usr/lib/python3.10/site-packages/Xlib/support/unix_connect.py", line 98, in _get_unix_socket
s.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/Xlib/support/unix_connect.py", line 123, in get_socket s = _get_tcp_socket(host, dno) File "/usr/lib/python3.10/site-packages/Xlib/support/unix_connect.py", line 93, in _get_tcp_socket s.connect((host, 6000 + dno)) ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/bin/xkeysnail", line 6, in <module> cli_main() File "/usr/lib/python3.10/site-packages/xkeysnail/init.py", line 62, in cli_main eval_file(args.config) File "/usr/lib/python3.10/site-packages/xkeysnail/init.py", line 6, in eval_file exec(compile(file.read(), path, 'exec'), globals()) File ".config.py", line 4, in <module> from xkeysnail.transform import * File "/usr/lib/python3.10/site-packages/xkeysnail/transform.py", line 16, in <module> def get_active_window_wm_class(display=Xlib.display.Display()): File "/usr/lib/python3.10/site-packages/Xlib/display.py", line 89, in init self.display = _BaseDisplay(display) File "/usr/lib/python3.10/site-packages/Xlib/display.py", line 71, in init protocol_display.Display.init(self, *args, **keys) File "/usr/lib/python3.10/site-packages/Xlib/protocol/display.py", line 89, in init self.socket = connect.get_socket(name, protocol, host, displayno)

File "/usr/lib/python3.10/site-packages/Xlib/support/connect.py", line 87, in get_socket return mod.get_socket(dname, protocol, host, dno) File "/usr/lib/python3.10/site-packages/Xlib/support/unix_connect.py", line 127, in get_socket raise error.DisplayConnectionError(dname, str(val)) Xlib.error.DisplayConnectionError: Can't connect to display ":0": [Errno 111] Connection refused

问题原因猜测

alacritty 和 xkeysnail 在正常的 linux + i3wm 都能打开的

远程 使用 xvnc 的方式 却打不开 ,感觉是 因为 xserver 的环境 变了么 ?

问题

  1. 现在大家都是怎么用 win 远程 i3wm 桌面环境 的呢 ? 需要安装哪些软件
  2. 有在 远程环境下 启动 xkeysnail 和 alacritty 成功的么 ?或者 说 这两个软件 限制如此 ,那么 ,linux 下还有没有其他 按键映射软件 是能在 远程环境下 能 正常工作的 ?
第 1 条附言  ·  2022 年 7 月 22 日
mstsc 进去后 以 xorg 的方式 登录 ,显示蓝背景 ,大概等个 3 4 分钟 ,就会弹出 如下错误

connecting to sesman on 127.0.0.0.1:3350
sesman connect ok
sending login info to session manager. please wait ...
login successfull fo user ifnk on display 10
started connecting
connection problem,giving up
some problem
error connecting to user session
第 2 条附言  ·  2022 年 7 月 22 日
我按照 @whitegerry 的方式 重新安装 了 xrdp ,现在使用 mstsc 以 xorg 的方式 能连接 了 ! alacritty 也能打开 了!

但是 xkeysnail 现在还是不能用 ,现在不报错 ,但是说 没有输入设备 ?

如下图 No keyboard devices specified via (--devices) option.
xkeysnail picks up keyboard-ish devices from the list below:

----------------------------------------------------------------------------------
Device Name Phys
----------------------------------------------------------------------------------
/dev/input/event0 Power Button LNXPWRBN/button/input0
/dev/input/event1 AT Translated Set 2 keyboard isa0060/serio0/input0
/dev/input/event2 VMware VMware Virtual USB Mouse usb-0000:02:00.0-1/input0
/dev/input/event3 VirtualPS/2 VMware VMMouse isa0060/serio1/input1
/dev/input/event4 VirtualPS/2 VMware VMMouse isa0060/serio1/input0
/dev/input/event5 py-evdev-uinput py-evdev-uinput

Okay, now enable remapping on the following device(s):

------------------------------------------------------------------------------
Device Name Phys
------------------------------------------------------------------------------
/dev/input/event1 AT Translated Set 2 keyboard isa0060/serio0/input0


就是我怎么 让 mstsc 的输入 也当成一个键盘 来供 xkeysnail 使用 呢 ?
第 3 条附言  ·  2022 年 7 月 22 日
现在我用 那个基于 xkeysnail 的 kinto.sh ,按键映射,他好像支持 xrdp ,

但是我这里启动起来 会报 /usr/bin/xhost: unable to open display ":10.0"

还是 关于 display 的错 ,

啊 ,这个有办法 解决么?
41 条回复  •  2023-12-11 15:03:16 +08:00
ScepterZ
   1
ScepterZ  
   2022 年 7 月 22 日
如果 vsc 能搞定就用 vsc 吧,现在 vsc remote 用的多就是因为它是在太简单了,啥都不用配置就能用,虽然功能稍微弱点,但是勉强能接受
975779964
   2
975779964  
OP
   2022 年 7 月 22 日
@ScepterZ 唉 我 是用 i3wm 的平铺功能 还有按键映射 ,不是 远程开发
ProPh3t
   3
ProPh3t  
   2022 年 7 月 22 日
Can't connect to display ":0" 两个问题看起来都是一个问题,即连接不到 DISPLAY:0,可以看看 VNC 下环境变量 DISPLAY 是不是 0 ,从这里排查.
975779964
   4
975779964  
OP
   2022 年 7 月 22 日
@ProPh3t 我设置了 DISPLAY=:0 后 ,然后 再次根据 报错提示 设置 环境变量 ,最后 报的错 是 这个
$ alacritty
thread 'main' panicked at 'Failed to initialize any backend! Wayland status: XdgRuntimeDirNotSet X11 status: XOpenDisplayFailed', /build/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/mod.rs:619:9
stack backtrace:
0: 0x55608278545f - <unknown>
1: 0x55608263957c - <unknown>
2: 0x556082758fb4 - <unknown>
3: 0x5560827877ba - <unknown>
4: 0x556082788702 - <unknown>
5: 0x556082788212 - <unknown>
6: 0x556082788186 - <unknown>
7: 0x556082788142 - <unknown>
8: 0x556082464f92 - <unknown>
9: 0x5560825dd4bf - <unknown>
10: 0x55608247ffe3 - <unknown>
11: 0x5560825d62c3 - <unknown>
12: 0x7fc3bbc29290 - <unknown>
13: 0x7fc3bbc2934a - __libc_start_main
14: 0x556082470d35 - <unknown>
15: 0x0 - <unknown>

先不提 alacritty ,这个 有别的命令行 terminal 替代 ,

请问 按键映射 有对应的替代么? 或者 xkeysnail 这个 报错 有办法 解决么 ?
muxueqz
   5
muxueqz  
   2022 年 7 月 22 日
@975779964 在 xvnc 里 echo $DISPLAY 看看?不要改 DISPLAY 的值

另外,xrdp 可能性能不好,也可以试试 x2go/nx 等方案
ProPh3t
   6
ProPh3t  
   2022 年 7 月 22 日
@975779964
你是怎么启动 x11vnc 的?是这样吗`$ x11vnc -display :0`?
975779964
   7
975779964  
OP
   2022 年 7 月 22 日
@ProPh3t 我在 linux 下是 直接 sudo systemctl enable --now xrdp 这样的就 没有管了 ,然后 在 win 下 是 用 mstsc 然后 有即个选项 ,我选择的是 xvnc 然后 输入用户名和密码就好了
975779964
   8
975779964  
OP
   2022 年 7 月 22 日
@muxueqz 我刚下载 了 x2go ,然后我想按 win+d 启动 程序 ,结果 直接 触发 win 的快捷键了, 请问 怎么 设置 不让触发 win 的快捷键呢 ?
haoliang
   9
haoliang  
   2022 年 7 月 22 日
我有过一次使用经验是,忘了是远程桌面还是 docker 化 chromium ,需要 xhost 的加持,具体命令忘了。楼主可以搜索下。
iamzuoxinyu
   10
iamzuoxinyu  
   2022 年 7 月 22 日
> 我刚下载 了 x2go ,然后我想按 win+d 启动 程序 ,结果 直接 触发 win 的快捷键了, 请问 怎么 设置 不让触发 win 的快捷键呢
@975779964 这个只能改 i3 的 leader key 了,你要习惯了 windows 键的位置,可以先在 windows 下将 win 键通过注册表重新映射成 alt 或其它,然后在 i3 里将 leader key 改成 alt 。

> 其中 使用 xorg 选项 输入 用户名密码后 , 就还是一样的蓝背景 ,过一会 说 连接拒绝之类的 ,无法 远程
或许是防火墙的问题?改下 ssh xforward 权限?

另外可以试试用 vcxsrv ,直接 ssh -X 做转发。
muxueqz
   11
muxueqz  
   2022 年 7 月 22 日
MaxTan
   12
MaxTan  
   2022 年 7 月 22 日
直接用 VcXsrv 或者 mobaxterm 自带的 x11 server

不过这样 wm 的 modkey 就不能用 win 键了,需要另外设定
zer
   13
zer  
   2022 年 7 月 22 日
nomachine 远程试过么?
whitegerry
   14
whitegerry  
   2022 年 7 月 22 日
同 archlinux + i3wm ,用的 xrdp ,没有配置过 tigervnc 。
alacritty 可以打开
whitegerry
   15
whitegerry  
   2022 年 7 月 22 日
xkeysnail 没有用过,另外远程连接用的是 xorg 。
975779964
   16
975779964  
OP
   2022 年 7 月 22 日
@whitegerry 你是怎么联上的呢? 我 虚拟机 装了 xrdp 和 tigervnc ,但是 远程 以 xorg 的方式 连 是 无法 连上的
whitegerry
   17
whitegerry  
   2022 年 7 月 22 日
@975779964 xrdp 安装参考了这个 gist 里的步骤: https://gist.github.com/GregaVrbancic/71f8e9891f4f70032a9e5882a88839ce ,
yaoyaomoe
   18
yaoyaomoe  
   2022 年 7 月 22 日 via iPhone
如果用 xorg 的话 archwiki 有说

Xorg backend
To use xorgxrdp instead for the backend, install the xorgxrdpAUR package.

Add allowed_users=anybody to /etc/X11/Xwrapper.config to allow anybody to start an X server.

之后建议看下现在所在的 display 号码 有时候分配的不一定是 0
zocome
   19
zocome  
   2022 年 7 月 22 日
mark ,同想用 xrdp 远程 arch+i3
beginor
   20
beginor  
   2022 年 7 月 22 日 via Android
搭车问一下,这样的 x11 用起来卡卡的,是不是没有硬件加速呢?

我记得微软的 hyperv 装 Linux 之后也是用 xrdp ,但是速度很快,非常流畅。
secondwtq
   21
secondwtq  
   2022 年 7 月 23 日
VNC 连接如果是用 VNC 自己的 X Server 的话,是不能使用 GPU 的,alacritty 整个就是绕着 GPU 加速做的,自然不能用
basncy
   22
basncy  
   2022 年 7 月 26 日
1. xrdp xvnc 前端 rdp(对应 mstsc), 后端 vncserver(比如 127.0.0.1:5900)
2. xrdp xorg 前端 rdp(对应 mstsc), 后端是 /usr/lib/Xorg. 跟那些半吊子教程讲的 ssh Xforward 有半毛钱关系.
3. anydesk, 有人试过吗?效果怎样.
whitegerry
   23
whitegerry  
   2022 年 8 月 20 日
@beginor xrdp 的硬件加速几乎等于没有,还是靠 cpu 。现在主力 nomachine ,因为笔记本是 hidpi 的屏,i3 设置好 hidpi ,又能 gpu 加速,使用体验比 xrdp 好多了。
whitegerry
   24
whitegerry  
   2022 年 8 月 20 日
一台物理机和一个 pve 的虚拟机都是 arch+i3 ,都有显卡加速,主力 nomachine ,备用 xrdp 。
whitegerry
   25
whitegerry  
   2022 年 9 月 8 日
@beginor xrdp 也可以用 gpu 加速,这两天弄出来了
975779964
   26
975779964  
OP
   2022 年 9 月 8 日
@whitegerry 我现在尝试了 nomachine ,他也不能 转发 我的 按键呢, 导致 xkeysnail 映射不成功

https://bbs.archlinuxcn.org/viewtopic.php?id=12716

我现在 特别 想要一个能 支持 xkeysnail 映射的 远程 软件
beginor
   27
beginor  
   2022 年 9 月 9 日
@whitegerry 怎么弄,有教程么?
whitegerry
   28
whitegerry  
   2022 年 9 月 9 日
@beginor 也不需要什么教程,arch 安装 xrdp 和 xorgxrdp-glamor 或者 nvidia 那个包就好了,client 可以用 freerdp 测试,参数 /gfx:AVC444
beginor
   29
beginor  
   2022 年 9 月 9 日 via Android
可惜 Ubuntu 没有这个包,另外这样能用微软远程桌面么?
whitegerry
   30
whitegerry  
   2022 年 9 月 23 日
@beginor 这两天又试了一下,linux 做 host, 核显 uhd610, 没有 parsec, 就用的 sunshine, 客户端安装 moonlight, 体验下来确实非常丝滑,就像在本机一样,比 parsec 的体验还好一点,这是没想到的。一直喜欢用的 nomachine 瞬间感觉就差了一大截。

我在办公室连家里,带宽设置 8Mbps, 画面质量和锐利度都很稳定。之前在家局域网用 windows 测试 parsec 的时候画面颜色和锐利度质量都会变。
beginor
   31
beginor  
   2022 年 9 月 23 日 via Android
@whitegerry 好吧,老哥你真能折腾。我还是 xrdp 凑合用吧
hanssx
   32
hanssx  
   2022 年 10 月 13 日
@975779964 楼主搞定了没,nomachine 有个问题是快捷键优先使用 host(控制端)的,好像还没办法设置

@whitegerry linux 做 host 是作为控制端吗? xrdp 用 gpu 加速能用 windows 的 mstsc.exe 连接吗?
whitegerry
   33
whitegerry  
   2022 年 10 月 13 日
@hanssx mstsc.exe 链接也可以用 gpu 加速,建议关闭 linux 端的 composer ,不然会有延时。
linux 做 host 指它作为服务端,控制端在客户机这边。
975779964
   34
975779964  
OP
   2022 年 10 月 13 日
@hanssx 搞定不了 ,这几款 远程快捷键应该都是用的 host(控制端) 的, 导致我 xkeysnail 按键映射不了 ,我现在放弃 了,我 目前的方案是 使用 win10 安装 虚拟机 linux , 然后 另一台电脑 win10 用 mstsc ,远程 这台 win10 ,然后 使用 虚拟机 linux 写代码, 这样他的按键 映射是 好用的
hanssx
   35
hanssx  
   2022 年 10 月 13 日
@whitegerry linux 的 composer 不会是 php 那个 composer 吧? sunshine 就是 moonlight 吧,有空试试。

@975779964 这样有点难受,我是用 nomachine ,也就 windows 那几个快捷键会占用,实在冲突的改一下也能用。
hanssx
   36
hanssx  
   2022 年 10 月 13 日
刚试了下,用 vnc 5900 端口那个作为 xrdp 是可以全局在 linux 下操作的,但是画面流畅度太低,应该是没法用或者没开硬件加速的原因。
whitegerry
   37
whitegerry  
   2022 年 10 月 14 日 via iPhone
@hanssx 不是,是合成器,比如 i3 用的 picom 那种。
whitegerry
   38
whitegerry  
   2022 年 10 月 14 日 via iPhone
@hanssx linux host 用 sunshine ,客户端用 moonlight 。
whitegerry
   39
whitegerry  
   2022 年 10 月 14 日 via iPhone   ❤️ 1
@hanssx xrdp 硬件加速是走 xorg 的,如果走 vnc 不如直接 realvnc ,那个是硬件加速的,效果跟 nomachine 类似,快捷键的问题我忘了 realvnc 是什么情况。
975779964
   40
975779964  
OP
   2023 年 12 月 9 日
@whitegerry 我 arch i3wm 下载了 sunshine ,然后 sudo sunshine ,配置好后,win10 下载了 moonlight 远程过去发现鼠标键盘都不能动是为什么呀? 你有没有遇到过,是怎么解决的?
icepie
   41
icepie  
   2023 年 12 月 11 日
sunshine 不需要 sudo 吧
Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
© 2026 V2EX · 107ms · 3.9.8.5