使用tramp-mode

如何开启tramp模式

C-x C-f /ssh:who@server.com:/path_on_server

打开后,然后M-x dired开启dired模式(tramp默认支持dired)

本人机子上,开启我的个站(已经将网站通过~/.ssh/config里头,给ip服务器取了别名lppgz,并指定了root用户)

C-x C-f /ssh:lppgz:/usr/share/nginx/html

通过emacs在远程服务器上操作更复杂的操作

参考这篇post

post思路提炼

思路1,emacs的emacsclient+ssh的socket转发+服务器上跑emacsserver

It has already been suggested that you connect a local emacsclient to a remote Emacs server over TCP. You could also try using SSH to forward the remote Emacs server's Unix socket (maybe in /tmp/emacs1000/server) to a local socket on your Mac (via ssh -L), and then connect to the local socket with emacsclient -s. Edit: never mind, this doesn't seem to work the way I thought it would. (Forwarding the Emacs server port to a remote machine and connecting to it opens an Emacs window on the server, which is not what you want.)

I prefer tmux + TUI emacsclient for working on remote machines. Having said that, I've always wanted to try configuring my emacs server process on my favorite remote Linux host to listen on an internet accessible TCP socket (as well as setting up authentication) and trying to connect it remotely using my GUI emacsclient running on my macOS. That could be a really slick way of accomplishing what you want. Your "native clipboard" problem can be solved. From a remote host you can send an OSC-52 escape sequence that good terminal applications can be configured to pass along to the native clipboard. It looks like "\e\e]52;c;" + your base64 encoded content. Google osc52.el for an example of how to use this in emacs. If you're in tmux you'll have to wrap that the OSC-52 sequence in a "device control" sequence, which for tmux looks like: "\ePtmux;" in order for tmux to pass the OSC-52 unmolested up to your terminal. You should check the Emacs Wiki iTerm2 page, which has some great info in now to get native hyper key support in a remote TUI emacs.

思路2,sshfs把远程的文件系统mount到本地

You can consider mounting remote files using sshfs. There should be a FUSE impl for os x