Files
SimpleRemoter/linux
yuanyuanxianganddeepseek-flash 4146c73657 Feature: Make Linux a copy_files_c2c destination
The C2C file transfer tool required both ends to be Windows clients. A Linux
client can already land the files: the Windows source worker builds every
entry name by plain string concatenation of dst_dir and the relative path, so
a POSIX dst_dir such as /tmp/recv arrives as "/tmp/recv\sub\file", which the
POSIX receiver normalizes to "/" and writes below an absolute path. What was
missing was the server gate and any way to tell whether the writes succeeded.

The server now accepts LNX/MAC destinations instead of rejecting them, and
validates dst_dir by destination type: an absolute Windows path for Windows
targets, an absolute POSIX path without backslashes for POSIX targets. The
paths and dst_dir arguments also reject embedded NULs, and a POSIX dst_dir is
converted to CP936 exactly so unencodable characters fail loudly instead of
silently becoming '?'.

To make receiver_ack meaningful, a Linux client that receives a C2C transfer
now reports what it wrote. It tracks the outcome per transferID, counting a
directory entry, the last chunk of a file and the completion packet of an
empty file as the three ways an item is settled, with done sets so that
source retries and the trailing completion packet never double count. When
every item is settled it sends one C2CSendResultPacket back on its main
connection under the new TOKEN_C2C_RECV_RESULT (176), with the first errno in
the win32err field and the mapped FEV2_* status. A dedicated token is used
instead of reusing 175 because a host can be the destination of one transfer
while being the source of another, and a destination result must never latch
the source side's done flag.

The server waits up to five seconds for that acknowledgement after the source
reports success, and only for destinations advertising the new
CLIENT_CAP_C2C_RECV_ACK capability bit (Linux only, macOS reports nothing).
A failed acknowledgement becomes -32011 with the status, errno and received
file count; a missing acknowledgement stays an error only for transfers that
actually moved bytes, since a transfer of empty files alone gives the
receiver nothing to learn totalFiles from. Windows destinations are unchanged
and skip the wait entirely.

Verified on the debug instance: Windows to Linux (WSL Ubuntu 24.04) with
subdirectories, an empty directory, a Chinese file name and a 3 MB binary
lands with matching SHA-256 and receiver_ack true; a Windows-style dst_dir
returns -32602; an unwritable POSIX destination returns -32011; the existing
Windows to Windows cases still pass with receiver_ack false and the same
latency.

Co-Authored-By: deepseek-flash
2026-10-27 19:22:12 +01:00
..

SimpleRemoter Linux Client

SimpleRemoter 的 Linux 客户端,支持远程桌面、远程终端、文件管理和进程管理功能。

功能特性

  • 远程桌面 - 实时屏幕截图传输,支持鼠标/键盘控制,支持多种压缩算法
  • 远程终端 - 基于 PTY 的交互式 Shell
  • 文件管理 - 远程文件浏览、上传、下载
  • 进程管理 - 查看和管理远程进程
  • 守护进程模式 - 支持后台运行 (-d 参数)

功能实现对比 (Linux vs Windows)

已实现

功能模块 Linux 实现 Windows 对应 状态
远程桌面 ScreenHandler.h ScreenManager.cpp ✅ 完整 (DIFF/RGB565/GRAY)
进程管理 SystemManager.h SystemManager.cpp ✅ 完整
文件管理 FileManager.h FileManager.cpp ✅ 完整
远程终端 PTYHandler (main.cpp) ConPTYManager.cpp ✅ 完整
心跳/RTT main.cpp KernelManager.cpp ✅ 完整
用户活动检测 ActivityChecker ActivityWindow ✅ 完整
系统信息采集 main.cpp LoginServer.cpp ✅ 完整
守护进程 daemonize() Windows 服务 ✅ 完整
剪贴板同步 ClipboardHandler.h ScreenManager.cpp ✅ 服务端↔Linux
V2 文件传输 FileTransferV2.h file_upload.h ✅ 服务端↔Linux
C2C 文件接收 FileTransferV2.h file_upload.h ✅ Windows/MCP → Linux(目标目录由服务端 dst_dir 指定,落盘后回执)
配置持久化 LinuxConfig INI 文件 ✅ 完整

未实现

功能模块 Windows 文件 命令 优先级 说明
会话管理 KernelManager.cpp COMMAND_SESSION 高 关机/重启/注销
下载执行 KernelManager.cpp COMMAND_DOWN_EXEC 高 下载并运行程序
服务管理 ServicesManager.cpp COMMAND_SERVICES 中 systemd 服务列表
键盘记录 KeyboardManager.cpp COMMAND_KEYBOARD 中 需要 X11/evdev
开机自启 auto_start.h - 中 systemd user service
窗口列表 SystemManager.cpp COMMAND_WSLIST 低 X11 窗口枚举
音频监听 AudioManager.cpp COMMAND_AUDIO 低 需要 PulseAudio/ALSA
摄像头 VideoManager.cpp COMMAND_WEBCAM 低 需要 V4L2
语音对讲 TalkManager.cpp COMMAND_TALK 低 双向音频传输
清除日志 KernelManager.cpp COMMAND_CLEAN_EVENT 低 清除 syslog
注册表管理 RegisterManager.cpp COMMAND_REGEDIT - Linux 不适用

开发优先级说明

高优先级 - 日常管理常用功能

  • 剪贴板同步:跨平台复制粘贴 ✅ 已完成
  • 会话管理:远程关机/重启
  • 下载执行:远程部署程序

中优先级 - 系统管理功能

  • 服务管理:查看/控制 systemd 服务
  • 键盘记录:输入监控
  • 开机自启:持久化运行

低优先级 - 硬件相关功能

  • 音频/摄像头/语音:需要额外硬件库支持

系统要求

显示服务器

类型 支持状态 说明
X11 / Xorg 支持 完全支持
XWayland 部分支持 X11 应用可用,原生 Wayland 应用不可见
Wayland (纯) 不支持 无法工作

重要: 本客户端使用 X11 API 进行屏幕捕获,不支持纯 Wayland 环境。 如果你使用 GNOME/KDE 等桌面环境,请在登录时选择 "Xorg" 或 "X11" 会话。

依赖库

必需 (远程桌面功能)

库 包名 (Debian/Ubuntu) 包名 (RHEL/Fedora) 用途
libX11 libx11-6 libX11 X11 核心库,屏幕捕获

推荐 (完整远程控制)

库 包名 (Debian/Ubuntu) 包名 (RHEL/Fedora) 用途
libXtst libxtst6 libXtst XTest 扩展,模拟鼠标/键盘输入

可选

库 包名 (Debian/Ubuntu) 包名 (RHEL/Fedora) 用途
libXss libxss1 libXScrnSaver 获取用户空闲时间
xclip xclip xclip 剪贴板同步 (文本/文件)

一键安装依赖

Debian / Ubuntu:

sudo apt update
sudo apt install libx11-6 libxtst6 libxss1 xclip

RHEL / CentOS / Fedora:

sudo dnf install libX11 libXtst libXScrnSaver xclip

Arch Linux:

sudo pacman -S libx11 libxtst libxss xclip

编译

编译依赖

# Debian/Ubuntu
sudo apt install build-essential cmake

# RHEL/Fedora
sudo dnf install gcc-c++ cmake make

编译步骤

cd linux
cmake .
make -j$(nproc)

编译成功后生成可执行文件 ghost。

使用方法

基本用法

./ghost [服务器IP] [端口]

守护进程模式

./ghost -d [服务器IP] [端口]

示例

# 前台运行,连接到 192.168.1.100:6543
./ghost 192.168.1.100 6543

# 后台守护进程模式
./ghost -d 192.168.1.100 6543

# 停止守护进程
kill $(cat ~/.config/ghost/ghost.pid)

远程升级

服务端选中一台 Linux 主机后点「升级程序」,即可把新的 ghost 推下去并自动重启。

服务端准备

按以下优先级取 ELF,前一级拿不到才看下一级:

顺序 来源 说明
1 settings.ini 的 [settings] LinuxClientPath 显式指定。配了但读不到会直接报错,不会偷偷换成别的版本
2 服务端程序目录下的 ghost_linux_amd64 换个文件即可,不必重编服务端
3 服务端 res\ghost_linux 项目通用的外部资源目录
4 内嵌资源 IDR_LINUX_GHOST 编译进服务端 exe(构建时取 linux/ghost),磁盘上什么都不用放
[settings]
LinuxClientPath=C:\build\ghost

第 4 级是编译时的快照,想换版本要么放到第 1~3 级,要么重编服务端。

只接受 64 位 x86_64 ELF(ELFCLASS64 + EM_X86_64),其它文件会在下发前被拒绝并提示。

下发格式

[COMMAND_UPDATE:1][size:8 LE][ELF:size][md5:32 ASCII 小写 hex]

Windows 客户端的同名命令没有摘要(走内存加载器/更新器),LNX 多出 32 字节 MD5。

客户端行为

  1. 校验长度、ELF magic、e_machine 与本机自身 ELF 头一致、MD5 匹配;
  2. 在自身所在目录写临时文件 .<名字>.new.<pid>(0755)并 fsync;
  3. 用 rename() 原子替换正在运行的二进制(Linux 允许替换执行中的 inode), 旧版本保留为 <名字>.old;
  4. fork + setsid + 关闭继承的 fd + 等待老进程退出,再用原始命令行 execv 新版本; 老进程以 g_bExit = S_CLIENT_UPDATE 正常退出,服务端立刻看到断线重连。

前提:客户端所在目录对运行用户可写(否则报「cannot create ...: Permission denied」)。 任何一步失败都不会退出进程,原因会写进客户端日志并发到服务端消息栏 (Linux client update failed)。

回滚:把 ghost.old 拷回 ghost 并重启即可(它会在下次升级时被覆盖)。

常见问题

Q: 远程桌面功能不工作

检查项:

  1. 确认使用 X11 会话

    echo $XDG_SESSION_TYPE
    # 应输出 "x11",如果是 "wayland" 则不支持
    
  2. 确认 DISPLAY 环境变量已设置

    echo $DISPLAY
    # 应输出类似 ":0" 或 ":1"
    
  3. 确认 X11 库已安装

    ldconfig -p | grep libX11
    # 应输出 libX11.so.6 的路径
    

Q: 鼠标/键盘控制不工作

安装 XTest 扩展库:

# Debian/Ubuntu
sudo apt install libxtst6

# RHEL/Fedora
sudo dnf install libXtst

Q: 警告 "MIT-SCREEN-SAVER missing"

这是一个无害警告,表示无法获取用户空闲时间。可以忽略,或安装 libXss:

# Debian/Ubuntu
sudo apt install libxss1

# RHEL/Fedora
sudo dnf install libXScrnSaver

Q: 如何在 Wayland 环境下使用?

目前不支持纯 Wayland。需要切换到 X11 会话。

方法1:登录时选择 X11 会话

  • 在登录界面点击用户名后,右下角会出现齿轮图标 ⚙️
  • 点击齿轮,选择 "Ubuntu on Xorg" 或 "GNOME on Xorg"

方法2:强制禁用 Wayland(推荐)

如果找不到齿轮图标,可以修改 GDM 配置强制使用 X11:

sudo nano /etc/gdm3/custom.conf

在 [daemon] 部分添加:

[daemon]
WaylandEnable=false

保存后重启系统:

sudo reboot

这样系统将始终使用 X11,无需每次手动选择。

KDE 桌面环境:

  • 登录界面选择 "Plasma (X11)"
  • 或编辑 /etc/sddm.conf 设置默认会话

Q: 如何检查当前会话类型?

# 查看会话类型
echo $XDG_SESSION_TYPE

# 查看显示服务器信息
loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type

配置文件

配置文件位于 ~/.config/ghost/config.conf,存储以下信息:

配置项 说明 示例值
InstallTime 首次安装时间 1709856000
PublicIP 公网 IP 缓存 1.2.3.4
GeoLocation 地理位置缓存 北京市
QualityLevel 屏幕质量等级 2 (Good / H264 1080P)

质量等级说明

值 等级 FPS 算法
-1 自适应 动态 动态
0 Ultra 30 DIFF
1 High 25 DIFF
2 Good 20 RGB565
3 Medium 15 RGB565
4 Low 10 RGB565
5 Minimal 8 GRAY

剪贴板同步

支持的操作

方向 操作 状态
服务端 → Linux 服务端 Ctrl+C,远程窗口 Ctrl+V ✅ 支持
Linux → 服务端 远程窗口 Ctrl+C,服务端 Ctrl+V ✅ 支持
Linux ↔ Linux (C2C) 远程A Ctrl+C,远程B Ctrl+V ❌ 暂不支持

支持的内容类型

类型 说明
文本 纯文本剪贴板内容
文件 单文件/多文件/文件夹,保留目录结构

依赖

需要安装 xclip 工具:

# Debian/Ubuntu
sudo apt install xclip

# RHEL/Fedora
sudo dnf install xclip

技术实现

  • 文本剪贴板:xclip -selection clipboard
  • 文件剪贴板:xclip -t text/uri-list 读取文件路径
  • 编码转换:服务端 GBK ↔ Linux UTF-8 自动转换

技术细节

屏幕捕获流程

  1. 使用 XCopyArea 将 root window 拷贝到离屏 Pixmap
  2. 使用 XGetImage 从 Pixmap 获取图像数据
  3. 转换为 BGRA 格式并翻转行序 (BMP 格式要求)
  4. 计算帧差异,仅传输变化区域

屏幕压缩算法

算法 带宽占用 说明
DIFF 4 字节/像素 原始 BGRA,最高画质
RGB565 2 字节/像素 16位色,节省 50% 带宽
GRAY 1 字节/像素 灰度,节省 75% 带宽
H264 - 暂不支持,自动降级为 RGB565

算法由服务端根据网络状况自适应选择,或可手动指定。

输入模拟

使用 XTest 扩展 (libXtst) 实现:

  • XTestFakeMotionEvent - 鼠标移动
  • XTestFakeButtonEvent - 鼠标点击
  • XTestFakeKeyEvent - 键盘输入

为何不支持 Wayland?

Wayland 出于安全考虑,禁止应用程序:

  • 捕获其他应用的屏幕内容
  • 模拟全局输入事件

这些限制使得传统远程桌面方案无法在纯 Wayland 下工作。