V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
qbuer
V2EX  ›  Visual Studio Code

vscode remote ssh 是如何实现 notty 登录的?

  •  
  •   qbuer · 2022-07-11 15:33:29 +08:00 · 1937 次点击
    这是一个创建于 653 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在使用 vscode-remote ssh 连接服务器时发现登录信息并不会记录在 /var/log/wtmp 、/var/log/utmp ,也就是 last 和 w 命令都看不到登录信息,使用 ps aux 查用户进程发现是以 notty 模式登录的。但实际上在 vscode 的终端中是有正常的 shell ,也可以正常执行命令的。

    很好奇 vscode 是如何实现这种效果的?

    7 条回复    2022-07-17 16:28:27 +08:00
    hwdef
        1
    hwdef  
       2022-07-11 15:52:13 +08:00
    猜测和 remote 的 server 端有关? remote 的终端里可以执行 code 之类的命令,,感觉不是普通的终端。
    qbqbqbqb
        2
    qbqbqbqb  
       2022-07-11 16:41:24 +08:00
    应该是 vscode-remote 通过 notty 的方式登录的之后,自己另外启动了一个 non-login 的 shell 。

    就像你直接在 Linux 的图形界面里启动多个 GUI 的终端模拟器,w 和 last 里也不会多出东西来一样。
    qbqbqbqb
        3
    qbqbqbqb  
       2022-07-11 17:02:23 +08:00   ❤️ 1
    utmp 是登录信息相关的记录(而且也不是所有方式登录都会记录,比如 ssh 非交互式登录就不会记录),和终端没有关系。Linux 里完全可以绕过登录流程创建虚拟终端( pty )。

    非交互式登录的 session ,utmp 里没有,也不代表完全追踪不到,比如使用 systemd 的发行版里用 loginctl 或者 systemctl status 还是能看到 vscode-remote 的 session 。
    corvofeng
        4
    corvofeng  
       2022-07-11 17:40:37 +08:00   ❤️ 1
    https://corvo.myseu.cn/2022/04/23/2022-04-23-%E6%94%B9%E9%80%A0upterm%E4%BB%A5%E6%94%AF%E6%8C%81VSCode%E8%BF%9C%E7%A8%8B%E8%BF%9E%E6%8E%A5%E4%BB%BB%E6%84%8F%E5%AE%B9%E5%99%A8/#Remote-SSH%E5%8A%9F%E8%83%BD

    建立 ssh 连接之后的通信的过程: remote 机器会下载一个 code-server 执行文件, 然后启动, VSCode 之后仅与服务器中的 code-server 通信.
    qbuer
        5
    qbuer  
    OP
       2022-07-11 20:10:39 +08:00
    受教了!
    kouhe3
        6
    kouhe3  
       2022-07-17 09:51:22 +08:00 via Android
    @corvofeng
    VSCode Desktop 是怎么和远程机器的 code server 通信的?
    远程开发时用的端口转发是 wstunnel 吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3751 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:35 · PVG 18:35 · LAX 03:35 · JFK 06:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.