I'm trying to use Sublime Text 2 as an editor when I SSH in to my work server, and I'm stumped. I found this http://urbangiraffe.com/2011/08/13/remote-editing-with-sublime-text-2/ (among many other posts) that looks like it might help, but I don't follow it exactly, particularly with what values I should put in for the remote variable in line 5. I set "/Users/path/to/local/copy" to my local root directory, but I don't know if that's right or if there's more to do. Any thoughts? I'm on OSX10.8
有三种方法:
Use SFTP plugin (commercial) http://wbond.net/sublime_packages/sftp - I personally recommend this, as after settings public SSH keys with passphrase it is safe, easy and worth every penny http://opensourcehacker.com/2012/10/24/ssh-key-and-passwordless-login-basics-for-developers/ Mount the remote as local file system using osxfuse and sshfs as mentioned in the comments. This might be little difficult, depending on OSX version and your skills with UNIX file systems. Hack together something like rmate which does file editing over remote tunneling using some kind of a local daemon (very difficult, cumbersome, but sudo compatible) http://blog.macromates.com/2011/mate-and-rmate/
此外,理论上,你可以在远程服务器上安装X11,并通过VNC或X11转发在那里运行Sublime,但这将非常缓慢。
您可以使用rsub,它的灵感来自TextMate的rate。从描述来看:
Rsub是Sublime Text 2的TextMate 2的“rate”特性的实现,允许使用SSH端口转发/隧道在远程服务器上编辑文件。
这里有一个关于如何正确设置它的好教程:(断开链接)http://log.liminastudio.com/writing/tutorials/sublime-tunnel-of-love-how-to-edit-remote-files-with-sublime-text-via-an-ssh-tunnel
作为@ubik回答的后续,以下是让“subl”命令在远程服务器上工作的三个简单(一次性)步骤:
使用Sublime包管理器在Sublime Text中安装rsub包 [Local]执行以下Bash命令(这将建立一个SSH隧道,这是rsub的秘密武器): printf "Host *\n RemoteForward 52698 127.0.0.1:52698" >> ~/.ssh/config 在远程服务器上执行以下Bash命令(这将安装subl shell命令): sudo wget -O /usr/local/bin/subl https://raw.github.com/aurora/rmate/master/rmate Sudo chmod +x /usr/local/bin/subl
瞧!你现在在SSH上使用Sublime Text。
你可以从服务器上用subl ~/test.txt打开Sublime Text中的示例文件
我在Windows上使用了4种方法:SFTP, WinSCP, Unison和Sublime Text在Linux上使用X11通过SSH转发到Windows(是的,你可以这样做而不需要混乱的配置和使用免费工具)。
如果你能在你的Linux机器上安装软件,第四种方法是最好的。
第四种方法:
MobaXterm
Install MobaXterm on Windows SSH to your Linux box from MobaXterm On your linux box, install Sublime Text 3. Here's how to on Ubuntu At the command prompt, start sublime with subl That's it! You now have sublime text running on Linux, but with its window running on your Windows desktop. This is possible because MobaXterm handles the X11 forwarding over SSH for you so you don't have to do anything funky to get it going. There might be a teeny amount of a delay, but your files will never be out of sync, because you're editing them right on the Linux machine.
注意: 当调用subl时,如果它抱怨某个库-确保你安装它们成功地从mobaxterm调用sublimetext。
如果你不能在你的Linux机器上安装软件,最好是Unison。为什么?
它是免费的 它的速度非常快 它是可靠的,并且不关心您使用哪个编辑器 您可以创建自定义忽略列表
SFTP
设置: 安装SFTP Sublime Text包。此软件包需要license支持。
创建一个新文件夹 打开它作为一个崇高的文本项目。 在侧边栏中,右键单击文件夹并选择Map Remote。 编辑sftp-config文件。json文件 右键单击步骤1中的文件夹,选择下载。 在本地工作。
在sftp-config中,我通常设置:
"upload_on_save": true,
"sync_down_on_open": true,
除了机器的SSH终端外,这给了我一个相当无缝的远程编辑体验。
温森
Install and run WinSCP Go to Preferences (Ctrl+Alt+P) and click on Transfer, then on Add. Name the preset. Set the transfer mode to binary (you don't want line conversions) Set file modification to "No change" Click the Edit button next to File Mask and setup your include and exclude files and folders (useful for when you have a .git/.svn folder present or you want to exclude build products from being synchronized). Click OK Connect to your remote server and navigate to the folder of interest Choose an empty folder on your local machine. Select your newly created Transfer settings preset. Finally, hit Ctrl+U (Commands > Keep remote directory up to date) and make sure "Synchronize on start" and "Update subdirectories" are checked.
从那时起,WinSCP将使您的更改保持同步。
使用SublimeText在本地文件夹中工作。只要确保Sublime Text设置为从正在编辑的文件中猜测行尾即可。
一致
I have found that if source tree is massive (around a few hundred MB with a deep hierarchy), then the WinSCP method described above might be a bit slow. You can get much better performance using Unison. The down side is that Unison is not automatic (you need to trigger it with a keypress) and requires a server component to be running on your linux machine. The up side is that the transfers are incredibly fast, it is very reliable and ignoring files, folders and extensions are incredibly easy to setup.
你可以试试我一直在研究的一种叫做“xeno”的东西。它将允许您通过SSH连接打开Sublime文本(或任何本地编辑器)中的文件/文件夹,并自动将更改同步到远程机器。它应该可以在几乎所有的POSIX系统上工作(我自己使用它从OS X连接到Linux机器并在Sublime Text中编辑文件)。它是免费的,开源的。我想要一些反馈。
For more information: it's basically a Git/SSH mashup written in Python that allows you to edit files and folders on a remote machine in a local editor. You don't have to configure kernel modules, you don't need to have a persistent connection, it's all automatic, and it won't interfere with existing source control because it uses an out-of-worktree Git repository. Also, because it's built on Git, it's extremely fast and supports automatic merging of files that might be changing on both ends, unlike SSHFS/SFTP which will just clobber any files with older timestamps.
I am on MacOS, and the most convenient way for me is to using CyberDuck, which is free (also available for Windows). You can connect to your remote SSH file system and edit your file using your local editor. What CyberDuck does is download the file to a temporary place on your local OS and open it with your editor. Once you save the file, CyberDuck automatically upload it to your remote system. It seems transparent as if you are editing your remote file using your local editor. The developers of Cyberduck also make MountainDuck for mounting remote files systems.
我一直在做一个叫GitSync的项目。它仍然需要一些改进,但它是开源的,我已经每天都在使用它好几年了。我还在开发一个原生OS X版本,我称之为GitSyncApp
现在它只支持OS X,但是它应该很容易添加对Linux的支持,可能也支持Windows。
它通过监视文件系统事件来工作,并使用git来同步本地机器和服务器上的项目文件夹。
我尝试了其他解决方案,如osx保险丝,扩展驱动器,传输,几个解决方案,使用rsync等。它们在小型项目中都能正常工作,但如果你要处理大量代码,它们就不适合我了。
许多文件系统选项都进行缓存以提高性能,这很好,但事实并非如此。比如,如果你和其他人一起工作,而其他人更改了服务器上的文件。
如果我在一个脆弱或缓慢的网络上,我也会遇到问题,最终会得到空文件。或者文件没有同步,缓存就会变得奇怪;希望你最近做过。使用git解决了这个问题,因为它检查每个提交的完整性。
两个额外功能:
每次保存都要提交一次。它不是特别有用,但如果你需要回到过去,你可以。 它适用于任何文本编辑器。
另一个类似于osxfuse的mac解决方案是只使用Panic Software的传输FTP客户端,它允许您将远程文件夹挂载为本地磁盘。它支持SFTP,非常安全。
我知道这很老了,但我有一个很酷的方法值得分享。
Conemu和WinSCP工具需要准备的内容。这些都是简单的指令
Open WinSCP.exe and login to my desired remote server (I have found that it's important to login before attaching ... ). In the preferences for WinSCP - two settings to change. Choose Explorer type interface and rather than Commander - so you don't see local files. Unless you want to (but that seems like it would suck here). Set up Sublime as your default editor. With ConEmu open, right click the tab bar and select the option Attach to.... A dialog box will open with your running applications. Choose, WinSCP and select OK. ConEmu will now have an open tab with WinSCP displaying your remote files. Right click on the WinSCP tab and choose New console.... When the dialog box opens, enter the path to the Sublime executable on your system. Before you press Start, In the box that says New console split select the radio button to right and set the percentage. I usually choose 75%, but you can customize this to your liking, and it can be changed later. Now you will see Sublime in the same window running to the right of WinSCP. In Sublime, from the View menu, choose Sidebar->Hide Sidebar, and bam, you now have remote files in exactly the same manner as you would locally - with a few caveats of course that comes with editing anything remotely. WinSCP is lightening fast though.
我有两个显示器-左边显示器显示Chrome浏览器,右边显示器显示代码编辑器。同样在ConEmu中,我创建了另一个选项卡并ssh到我正在工作的站点,所以我可以远程运行gulp或grunt,也可以从命令行操作文件。认真加快发展。
这是一张截图:
根据你的具体需要,你可以考虑使用bt同步。在你的家庭电脑和工作电脑上创建一个共享文件夹。在你的家庭电脑上编辑文件(使用Sublime或其他你喜欢的工具),当你保存时,它们会自动同步。BitTorrent Sync不依赖于存储文件的中央服务器(如Dropbox等),所以理论上你应该清楚由于第三方存储敏感信息的任何问题。
你可以使用sftp挂载远程目录在你的位置机器上,然后简单地打开文件使用Sublime文本你通常会。
要使用sftp挂载远程目录,在Linux文件管理器上输入以下命令;
sftp://user@remote_box.com:22/home/user/code_directory
它可能看起来很慢,这取决于你的网速。但这对我很管用。
一个对我来说非常有用的解决方案——在Mac上进行本地编辑,然后让文件自动同步到远程机器上
Make sure you have passwordless login to the remote machine. If not, follow these steps http://osxdaily.com/2012/05/25/how-to-set-up-a-password-less-ssh-login/ create a file in ~/Library/LaunchAgents/filesynchronizer.plist, with the following content: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>filesynchronizer</string> <key>ProgramArguments</key> <array> <string>/usr/bin/rsync</string> <string>-avz</string> <string>/Users/USERNAME/SyncDirectory</string> <string>USERNAME@REMOTEMACHINE:~</string> </array> <key>WatchPaths</key> <array> <string>/Users/USERNAME/SyncDirectory</string> </array> </dict> </plist> In a terminal window run launchctl load ~/Library/LaunchAgents/filesynchronizer.plist That's it. Any changes to any files in ~/SyncDirectory will be synchronized to ~/SyncDirectory on the remote machine. Local changes will override any remote changes.
这将创建一个监视SyncDirectory的launchd作业,当有任何更改时,将运行rsync将该目录同步到远程计算机。
这是本地编辑远程主机上的文件的最简单的方法,您之前已经设置了ssh到远程IP
# issue on local box
sudo apt-get install sshfs # on local host install sshfs ( linux )
# on local box create secure mount of remote directory
export REMOTE_IP=107.170.58.249 # remote host IP
sshfs myremoteuserid@${REMOTE_IP}:/your/remote/dir /your/local/dir # for example
完成了! !
现在在本地主机上开始编辑文件…当你在本地列出目录时,它可能不会列出任何东西,直到你CD到子目录或列出一个特定的文件…延迟加载…这不会影响编辑文件
subl /your/local/dir/magnum_opus.go # local file edit using sublime text
上面是编辑远程文件
/your/remote/dir/magnum_opus.go # remote file on box $REMOTE_IP
对于OSX或Windows,可以在数字海洋上看到这个来自好心的人的啧啧声
使用FileZilla
这适用于Mac和Windows用户(我在Mac上使用)。多年来,我使用了列出的几个答案,发现FileZilla很适合我在有SSH访问权限的远程主机上编辑文件时的需求。它的设置也很快。
我配置一个新的服务器连接 连接到服务器 右键点击我想编辑的文件,选择查看/编辑。
这会打开我的默认编辑器(Sublime),但它可以与任何编辑器一起工作 已安装的编辑器。
一旦我保存了文件,Filezilla会自动提示我是否要“将该文件上传到服务器”,我点击“是”,然后它就更新了。
推荐文章
- Github权限被拒绝:ssh添加代理没有身份
- 如何修复/转换崇高文本的空间缩进?
- 警告:未受保护的私钥文件!当尝试SSH到Amazon EC2实例时
- 如何设置ssh超时时间?
- 如何在SSH上使用Sublime
- 使用Git GUI或SSH -keygen的SSH私钥权限太开放
- 在gitlab上被拒绝许可(公钥)
- 使用脚本自动输入SSH密码
- 在Linux中是否有办法继续中断的scp(安全拷贝)命令进程?
- 为什么SSH远程命令得到的环境变量比手动运行时少?
- 将Keypair添加到现有的EC2实例中
- 如何解决“sign_and_send_pubkey:签名失败:代理拒绝操作”?
- 对于未设置密码的OpenSSH私钥,如何添加密码?
- 'heroku'似乎不是一个git存储库
- 如何使标尺始终显示在崇高的文本2?