我当前在远程 Web 服务器上编辑文件的解决方案是使用 Fetch 浏览远程计算机,并使用 TextWrangler 进行编辑。但是由于我在远程计算机上使用命令行变得更加自如(但不太习惯使用 VIM...),我希望能够在远程计算机上输入类似“open filename.txt”的内容并在我的本地计算机上打开 TextWrangler。我听说过“反向隧道”这个术语作为一种选择,但我不知道下一步该怎么做。非常感谢任何建议 - 谢谢!
My current solution for editing files on a remote web server is to use Fetch to browse the remote machine and TextWrangler to make the edits. But since I'm getting more comfortable navigating the command line on the remote machine (but not comfortable enough to use VIM...), I'd like to be able to type something like 'open filename.txt' on the remote machine and have TextWrangler open up on my local machine. I've heard the term "reverse tunneling" tossed around as an option, but I have no idea what to do next. Any suggestions are greatly appreciated - thanks!
发布评论
评论(6)
就我个人而言,我使用 Cyberduck 作为我的 S/FTP 浏览器。在 Cyberduck 的首选项中,您可以定义默认文本编辑器来编辑远程文件。现在,当我选择一个文件时,只需按 Cmd+K,该文件就会在 TextWrangler 中打开。每当我保存时,更改都会自动传输到远程文件。
Personally, I use Cyberduck as my S/FTP browser. In Cyberduck's preferences, you can define a default text editor to edit remote files. Now I can just hit Cmd+K when I have a file selected, and it will open up in TextWrangler. Whenever I save, the changes are automatically transferred to the remote file.
我实际上想做同样的事情,但没有人写下来,所以我今天才弄清楚。
其中有 2 个必需部分和 3 个可选部分:
您需要能够从本地 ssh 到远程来运行命令,并且您需要能够ssh 从远程到本地,以便它可以向 TextWrangler 发送命令。
要设置 ssh 隧道,您需要在本地计算机上运行如下命令:
-f 和 -N 标志将 ssh 置于后台,并将您留在您的计算机上。 -R 标志将远程计算机上的端口绑定到本地计算机上的端口。通过端口 10022 联系远程计算机的任何内容都将发送到本地计算机上的端口 22。远程端口可以是任何你想要的,但你应该选择一个端口> > 1024 以避免冲突,因此您不必成为 root。我选择 10022,因为它类似于 ssh 的默认端口 22。将括号替换为您的用户名和计算机名称。
您需要在登录后运行一次。为了让您自己更轻松地执行该命令,您可以在 bash 配置文件中添加别名。将以下内容添加到本地
~/.bash_profile
:当然,您可以选择您喜欢的任何别名。
设置隧道后,您可以在远程计算机上使用如下命令:
-p 标志表示使用端口 10022(或您之前选择的任何端口)。这将导致远程计算机连接到本地计算机并执行双引号中的命令,而无需打开交互式 ssh 会话。引号中的命令是您在本地计算机上运行以在 TextWrangler 中打开远程文件的命令。
为了使命令更容易执行,您可以在 bash 配置文件中添加一个函数。将以下内容添加到您的远程
~/.bash_profile
:这是假设您没有在远程计算机上安装 TextWrangler 命令行工具。如果这样做,您应该将该函数命名为
edit
以外的名称。例如,tw
。这里,${1:0:1}
查看函数第一个参数的第一个字符,它应该是文件路径。如果它不是以/
开头,我们通过在开头添加当前工作目录 (pwd
) 来找出绝对路径。现在,如果您在/home/jdoe/some/directory/
中的远程计算机上运行edit some/other/directory/file.txt
,则以下内容将在本地计算机上执行:最后,您应该在两个方向上设置 ssh 密钥,这样就不会每次都提示您输入密码。这是其他人写的指南: http://pkeck.myweb.uga.edu/ssh/
I was actually looking to do the same thing, and no one had written it up, so I figured this out today.
There's 2 required and 3 optional parts to this:
You need to be able to ssh from local to remote to run the commands, and you need to be able to ssh from remote to local so it can send commands to TextWrangler.
To set up the ssh tunnel, you need to run a command on your local machine like:
The -f and -N flags put ssh into the background and leave you on your machine. The -R flag binds a port on the remote computer to a port on your local computer. Anything contacting the remote machine on port 10022 will be sent to port 22 on your local computer. The remote port can be anything you want, but you should choose a port > 1024 to avoid conflicts and so you don't have to be root. I chose 10022 because it's similar to ssh's default port of 22. Replace the brackets with your username and machine name.
You'll need to run that once after you log in. To make the command easier on yourself, you can add an alias in your bash profile. Add the following to your local
~/.bash_profile
:Of course, you can choose whatever alias name you like.
Once you've set up the tunnel, you can use a command like this on the remote machine:
The -p flag says to use port 10022 (or whichever port you chose earlier). This will cause the remote machine to connect to your local machine and execute the command in the double quotes without opening an interactive ssh session. The command in the quotes is the command you would run on your local machine to open the remote file in TextWrangler.
To make the command easier on yourself, you can add a function in your bash profile. Add the following to your remote
~/.bash_profile
:This is assuming that you don't have the TextWrangler command line tools installed on the remote machine. If you do, you should name the function something other than
edit
. For example,tw
. Here,${1:0:1}
looks at the first character of the first parameter of the function, which should be the file path. If it doesn't begin with/
, we figure out the absolute path by adding the current working directory (pwd
) to the beginning. Now, if you're on the remote machine in/home/jdoe/some/directory/
and you runedit some/other/directory/file.txt
, the following will be executed on your local machine:Lastly, you should set up ssh keys in both directions so you're not prompted for a password every single time. Here's a guide someone else wrote: http://pkeck.myweb.uga.edu/ssh/
我认为这不允许从命令行打开,但是
Eclipse 与 Remote-System-Explorer 还支持通过 ssh 连接编辑文件
I dont think this will allow opening from the command-line, but
Eclipse with Remote-System-Explorer also supports editing of files via ssh connection
我认为你指的是通过 ssh 进行的“X11 转发”。查看 ssh_config(5) 联机帮助页进行配置(或者仅使用带有“-X”参数的“ssh”)。据我所知,这仅适用于 X11 程序(gvim、xemacs 等),因为编辑器实际上在您连接的主机上运行 - 只有显示内容发生在您的本地计算机上。所以 TextWrangler 不是一个选择,因为它不是 X11 程序。
我使用 Interarchy(来自 nolobe)进行远程编辑。它是一个相当先进的 ftp/sftp 客户端,为您提供远程文件的查找器样式视图,并允许您使用您最喜欢的编辑器来处理这些文件。
如果您不想为这样的程序付费,您也可以使用密歇根大学提供的一个名为“Fugu”的开源程序。
I think what you're referring to is called "X11 forwarding" over ssh. Take a look at the ssh_config(5) manpage for configuration (or just use 'ssh' with the '-X' parameter). As far as i know, this does only work with X11 programs (gvim, xemacs, etc.), because the editor is actually running on the host you're connecting to - only the display stuff happens on your local machine. So TextWrangler is not an option, because it's not an X11 program.
I use Interarchy (from nolobe) for remote editing. It's a fairly advanced ftp/sftp client that gives you a finder-style view of your remote files and allows you to use your favourite editor to work on those files.
If you don't like to pay for such a program, there's an Open-Source program called "Fugu" available from the Univerity of Michigan which you can also use.
FileZilla 也提供此功能。 您可以在此处下载。连接到 sftp 后,您可以右键单击文本文件并使用您选择的文本编辑器打开它。
FileZilla offers this functionality as well. You can download it here. Once you've connected to your sftp you can right-click on the text file and open it with the text editor of your choice.
最小答案
您可以使用 Applescript。因此,从命令行执行以下命令:
Notes
<代码>
osascript <
然后像这样调用脚本:
<代码>
绑定 '"\et":"sh ~/bin/textwrangler.sh \"sftp://myusername:@my.server:22222/\""'
现在,您可以通过按
Alt-t
生成大部分命令Minimal answer
You can use Applescript. So from the command line execute this:
Notes
osascript <<EOF
tell application "TextWrangler"
activate
open location {"$1"}
end tell
EOF
Then invoke the script like this:
bind '"\et":"sh ~/bin/textwrangler.sh \"sftp://myusername:@my.server:22222/\""'
Now you generate the majority of the command by pressing
Alt-t