tramp-mode

一般编辑文件

  • 用法:

    1
    2
    3
    
    C-x C-f /ssh:username@server.net#Port:path/to/file.txt RET
    eg: /ssh:sawyer@localhost#13039:~/          --> for directories编辑目录
    eg: /ssh:sawyer@localhost#13039:~/book.txt  --> for files编辑文本

sudo

  • 用法:

    1
    2
    
    C-x C-f /ssh:username@hostname#Port|sudo:hostname:path/to/file.txt RET
    eg: /ssh:sawyer@localhost#13039|sudo:localhost:~/book.txt
  • 格式

    • (/sshx:remote-host)|(sudo:remote-host):(/path/to/file) RET
    • 解析

      • /sshx:remote-host : 说明要远程到 remote-host 机器
      • sudo:remote-host : 说明要在 remote-host 机器上使用 sudo 权限
      • 两组操作通过 "|" 连接起来

ssh + sudo 联用

参考: Open file via SSH and Sudo with Emacs - Stack Overflow

通过 "|" 连接多个 tramp 操作

老用法:

1
C-x C-f /sshx:host|sudo:host:/etc/

emacs >= 27 新用法:

1
C-x C-f /ssh:host|sudo::/etc/

好处: 少写一次 host(主机名)

windows 上

使用 sshx 和 scpx

zsh + tramp

ssh server 端使用 zsh, 会导致 tramp 卡住(stuck)的问题

参考:

解决方法:

  1. 简单解决方法:

    • 使用 /sshx 而不是 /ssh
    • 因为 sshx 使用的是 /bin/sh 而不是 /bin/zsh
  2. 修改 .zshrc

ssh 卡住问题

使用 sshx 协议可以提升速度