We have an all Windows network and I'm trying to get Tortoise Mercurial up and running over SSH for a central repo for our small team to use. I can get it working for the most part but plink/tortoiseplink hang AFTER executing commands successfully (clone/push etc.)
I've set up Freesshd on our Widnows 2008 rc2 server along with Tortoise Hg. I've generated myself a public/private key on the server (was having issues generating on the client) using PuttyGen. Private key I copied to my client and updated mercurial.ini. Public key I renamed and updated Freesshd to point at the folder containing the public keys.
On the client side I have registered my private key with Pageant, created a session in Putty along with pointing it at my private key and saved it.
When I use Putty to make my initial connection, things start to go odd.
I get a command prompt for user name (no prompt for password) and, at the command prompt (after authentication), I can't type.
Perhaps an issue with Putty. I'll try using Tortoise via (TortoisePlink.exe).
In mercurial.ini I have:
[ui]
ssh = "C:\putty\TortoisePlink.exe" -ssh -2 -batch -C -i C:\Users\Jude.ssh\JudePrivate.ppk
If I use the console I can clone the repo but it hangs AFTER doing everything. Using --debug, the last line is:
3 files updated, O files merged, 0 files removed, 0 files unresolved
Kind of what I would expect as the files do get clones. But then I can't do anything else. Ctrl+C does nothing and I have to kill the process. (Which by the way, then shows the Ctrl^C at the command prompt as well as the rest of the keyboard mashing).
The repo gets cloned, the correct version of the files appear but the console window doesn't close or give me back control.
If I try using the Hg Workbench, I get a similar issue. I can clone and push - it actually happens - but using the GUI I get:
% hg --repository C:\repositories\HgTest push --debug
ssh://Jude#dev01:22/d:/repositories/hgtest
pushing to ssh://Jude#dev01:22/d:/repositories/hgtest
running "C:\putty\TortoisePlink.exe" -ssh -2 -batch -C -i
C:\Users\Jude\.ssh\JudePrivate.ppk Jude#dev01 -P 22 "hg -R d:/repositories/hgtest serve --stdio"
sending hello command
sending between command
remote: 145
remote: capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch stream unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024
remote: 1
query 1; heads
sending batch command
searching for changes
all local heads known remotely
no changes found
sending listkeys command
checking for updated bookmarks
sending listkeys command
The green bar at the top of the Workbench says "Pushing to ssh://Jude#dev01:22/d:/repositories/hgtest..." as does the status bar at the bottom. I left it like this all weekend and when I came back it was still like it. I can still use the Hg Workbench (kind of) but can't use pull/push/clone. Trying to close the Hg Workbench results in the message (in status bar) Sync tab cannot exit and I can't close the app. Killing TortoisePlink.exe (or Plink.exe, whichever I try) frees up the app I can use it or close it as normal.
Initially I thought it was a problem with TortoiseHg or TortoisePlink but downloading Plink from the Putty site results in the same.
To clarify:
- I can push/clone via SSH and no password prompt
- I can do this via the command line or the Hg Workbench
- Irrespective of which method I use (or Plink.exe or TortoisePlink.exe) the process needs to be manually killed.
Software used + versions
Client (Windows Vista 32bit)
Tortoise Hg 2.3 (merc 2.1, Python 2.6.6)
Plink 0.62
Server - (Windows 2008 server rc2)
FreeSSHd 1.2.4
Same Tortoise as above
Lots of searching has yielded nothing of use. I've tried all suggestions I've seen (even if marginally related) but to no avail. As the actual functions are working I assume I've set up correctly the keys, SSH, Tortoise etc.
I'm hoping I'm missing a simple option somewhere but I suspect that it's awaiting some kind of user prompt.
Fingers crossed :)
=== UPDATE ===
I've found the event log for Putty (right click putty console window, voila, "Event Log" option. Once I've loaded the session and clicked open, I get the console window and a login as: prompt. After typing my name and hitting return, I get:
Reading private key file "C:\Users\Jude\.ssh\JudePrivate.ppk"
Pageant is running. Requesting keys.
Failed to get reply from Pageant
Offered public key
Offer of public key accepted
Sent public key signature
Access granted
Opened channel for session
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
And it's at this stage I the command prompt changes to c:\Windows\system32> and can't type anything.
=== UPDATE 2 ===
Using plink I do the following at the console:
plink -v -ssh Jude#dev01 "cmd /c echo hello"
and, as well as all the info -v gives, I see hello then Server sent command exist status 0 and Disconnected: All channels closed. This is what I would expect.
If I do it with tortoiseplink, `tortoiseplink-v -ssh Jude#dev01 "cmd /c echo hello"' I see nothing returned or written to the window and I get a command prompt again.
This implies SSH is working as is the alias (dev01). But should I see something when using TortoisePlink?
Typing hg clone --verbose -- ssh://Jude#dev01/d:/repositories/hgtest C:\repositories\test again fetches the files, copies them to the test folder but then doesn't return the command prompt. Last line is 3 files updated... etc.
=== UPDATE 3 ===
It seems hg.exe is spawned by FreeSSHd on the server and it does close/finish. When the hg.exe process is killed on the server, the client (console/clone dialogue box) behaves and finished the command gracefully.
To clarify:
I use clone from command line or HG Workbench and specify repo alias
According to the logs everything is fine, I'm authenticated, the files are pulled down via SSH and copied to the local repo I specified in 1
At this point it hangs - whether the console or HG Workbench or right click/clone option.
Using Process Explorer on the server allows me to kill hg.exe spawned by the FreeSSHd service
As soon as I do this the client says "command completed successfully".
So, it now seems to be an issue with Tortoise Hg on the server. Maybe FreeSSHd and Tortoise don't play well together... I suppose I'll reinstall everything...
=== UPDATE 4 ===
It seems I'm not the only one with this issue. I had spotted this before on SO but it wasn't relevant at the time. However, now I'm getting the same problem: Mercurial over ssh client and server on Windows
That problem wasn't solved (two years ago) so shall I keep this question open?
First of all - read docs!
hg help urls
Valid URLs are of the form:
....
ssh://[user#]host[:port]/[path][#revision]
Plink uses -l option for username
Debug successful ssh-connect (and usable path) with pure TortoisePlink, remove all unnecessary options
Related
1st I followed the answer at this thread: How to run ssh-add on windows?
2nd typed this: ssh-add .ssh/gitea_key
It worked for git bash, but not for Sourcetree.
After turning on the ssh agent, Sourcetree still asks for the password EVERY TIME I open it or close the Options. This is pure madness! In addition now it gives me this error:
'ssh-agent' failed with code -1: Sstem.ComponentModel.Win32Exception: Access is denied 0
I just want it to save the password, this is crazy hard or almost impossible to achieve. This is so ridiculous.
I have a headless file server on which I store and manage downloads and media, but occasionally I have to transfer small files back to my computer (Mac, using bash shell). The problem is that some files have more user-friendly names and commonly have spaces in them, and they are buried in the file directory hierarchy I have set up on my server.
When I'm using scp from my local machine, I don't have tab completion, so I have to manually type out the entire path and name with spaces escaped. When I ssh into the server first, the command:
scp /home/me/files/file\ name\ with\ spaces.png Me#localhost:/Users/Me/MyDirectory
fails with the error "Permission denied, please try again" even though I'm entering my local machine user password properly.
I've learned a little bit of sftp since I've been told that may be a better tool for file transfer. However, the utility seems outdated and I still don't have tab completion after establishing a connection to the server (on my Terminal when pressing Tab I just get a tab character).
My question is this: what can I do to allow tab completion while using scp from my Mac? Or am I using incorrect syntax for scp while in an ssh session, and is there something in that command I should fix? Or, is there a (better? newer?) tool other than sftp that would offer tab completion on a server?
Finally, if none of these problems have simple solutions, is there some package I could install (e.g. a completion package from Homebrew or the like) that would facilitate better tab-completion with any of these commands?
Looks to me like this is some incorrect scping.
This is the format of the command
scp ./localFile.txt remoteUser#remoteHost:/remoteFile.txt
You were so close, but you have localhost set where you should have your remoteHost.
localhost is the name that resolves to the machine that you are currently on - so in your workflow, you are sshing to a machine, and then trying to scp that file to the same machine you are already sshd into.
What you need to do, is figure out the IP address, or the physical host name of the computer that you are trying to connect to, and use that instead.
scp ./localFile.txt remoteUser#192.168.1.100:/remoteFile.txt
# where 192.168.1.100 would be the IP of your Mac
I am assuming the reason you were getting permission denied, was because you were using your the login credentials for you mac, but unknowingly trying to login again to your headless machine.
I'm attempting to clone a repo from my BitBucket account to my Windows 10 laptop (running GitBash). I've completed all of the steps necessary to connect (set up my SSH key, verified by successfully SSHing git#bitbucket.org, etc). However, whenever I attempt to clone a repo, the prompt continually hangs up after confirming that I want to cache Bitbucket's key.
User#Laptop MINGW64 /C/Repos
$ git clone git#bitbucket.org:mygbid/test.git
Cloning into 'test'...
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) y
No files are cloned, and the result is an empty repo. Trying to initiate a git pull origin master from this repo also asks to cache the key, then hangs with no feedback. Despite not asking for the key to be cached when I do a test SSH, git operations always ask for the key every time before failing.
With no error messages to work with, I'm really at a loss as to what is wrong. I've tried multiple repos, including very small ones, with no success at all.
I had this problem when cloning a repo on Windows 10 too.
I got around it by using the Putty GUI to SSH to the server in question (in your case: bitbucket.org) then clicked 'Yes' when the prompt asks if you want to save the server key to the cache. Running the clone command again then worked for me!
Open Putty
Type in the Host Name (like bitbucket.org)
Click Open
Click yes in the popup to cache the host key
Close Putty
I managed to get it working by running plink directly, after pageant is running use the plink command directly - plink.exe -agent -v git#github.com then after this git works without hanging.
To do this from powershell open a powershell window and paste in the following:
echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh git#github.com
echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh git#gist.github.com
echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh git#bitbucket.org
or with PuTTY standalone version:
echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh git#github.com
echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh git#gist.github.com
echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh git#bitbucket.org
Also worth knowing is that putty stores known hosts under a registry key:
HKEY_CURRENT_USER\SoftWare\SimonTatham\PuTTY\SshHostKeys
To shortcut the above you could put the following in a .reg file and run it:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\SimonTatham\PuTTY\SshHostKeys]
"rsa2#22:github.com"="0x23,0xab603b8511a67679bdb540db3bd2034b004ae936d06be3d760f08fcbaadb4eb4edc3b3c791c70aae9a74c95869e4774421c2abea92e554305f38b5fd414b3208e574c337e320936518462c7652c98b31e16e7da6523bd200742a6444d83fcd5e1732d03673c7b7811555487b55f0c4494f3829ece60f94255a95cb9af537d7fc8c7fe49ef318474ef2920992052265b0a06ea66d4a167fd9f3a48a1a4a307ec1eaaa5149a969a6ac5d56a5ef627e517d81fb644f5b745c4f478ecd082a9492f744aad326f76c8c4dc9100bc6ab79461d2657cb6f06dec92e6b64a6562ff0e32084ea06ce0ea9d35a583bfb00bad38c9d19703c549892e5aa78dc95e250514069"
"rsa2#22:gist.github.com"="0x23,0xab603b8511a67679bdb540db3bd2034b004ae936d06be3d760f08fcbaadb4eb4edc3b3c791c70aae9a74c95869e4774421c2abea92e554305f38b5fd414b3208e574c337e320936518462c7652c98b31e16e7da6523bd200742a6444d83fcd5e1732d03673c7b7811555487b55f0c4494f3829ece60f94255a95cb9af537d7fc8c7fe49ef318474ef2920992052265b0a06ea66d4a167fd9f3a48a1a4a307ec1eaaa5149a969a6ac5d56a5ef627e517d81fb644f5b745c4f478ecd082a9492f744aad326f76c8c4dc9100bc6ab79461d2657cb6f06dec92e6b64a6562ff0e32084ea06ce0ea9d35a583bfb00bad38c9d19703c549892e5aa78dc95e250514069"
"rsa2#22:bitbucket.org"="0x23,0xb9b88df3578371a7eb80c78bcda14fb30da436f11ca932a5fd5a8b6adfcc681df7a59cb4cb7ac966d9eac11daa38ebdbc0a6582a210ed4ee95a8d101c4abc925e942ab47535d64f9a5b3b68035c2ea1e900d709a1e8ea938718f532f9805a190446b92bac3040126225ae9d8374bc2008f106979d631734c7453f78c70091f4783b288869cb3c1941a784cd9baad823be27333833dc1f488a45b85952be75cf0a64965662302e3915378dcd5cfcd3ec903d804a29dff2fdf19df5deba4534b09e4dea6e44f152e339b3c43be98ddadfc56533192e216a3d673f00b4aa9cc9e7870acd8b6adb7e0feb77f2292fc2dede94819def3eb1e785541a06ab31ccf725f"
putty-hosts.reg gist
To workaround this problem I configured GitBash to use plink with -batch option. The option disables all prompts - the plink will terminate without hanging and won't add any key fingerprint to cache.
To add -batch parameter to plink command executed by GitBash you can set a git config option:
git config --global core.sshCommand "plink -batch"
Or set GIT_SSH_COMMAND environment variable.
The output when you cloning a repo from unknown host will be similar to this:
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
Connection abandoned.
fatal: Could not read from remote repository.
After this message you can add a key to cache with command:
echo y | plink git#bitbucket.org
REMARK: Please check if plink is in your PATH. Alternatively use UNIX-like path in the GitBash config option, e.g.:
/c/Program\ Files/PuTTY/plink.exe -batch
Even after performing the workaround mentioned in other answers, you may encounter an error like:
FATAL ERROR: Disconnected: No supported authentication methods available (server sent: publickey)
To solve both problems at once, change git bash to use SSH instead of PuTTY by adding the following to your ~/.profile file (C:\Users\<Username>\.profile). If you don't already have this file, then create a new file with this line.
GIT_SSH="/usr/bin/ssh.exe"
Then open a new git bash window and try your git clone or git pull again.
Note that this may require you to create an SSH key if you don't already have one. To do this, follow the instructions on the Bitbucket site.
See this SO question for related info.
In your git bash shell, check for existence of GIT_SSH:
echo $GIT<tab><tab>
If it exists and is set to putty, execute:
unset GIT_SSH
You'll probably want to put this into one of the git bash startup scripts.
This is NOT a universal solution. It worked in our particular case.
It sounds a bit silly, but after trying all of the above, I decided to reinstall Git Bash with default options and it worked.
If you use KiTTY (instead of PuTTY), it has -auto-store-sshkey argument.
So, you can set GIT_SSH_COMMAND (or git config --global core.sshCommand) to something like c:/KiTTY/klink.exe -auto-store-sshkey.
The output still contains information about new key and the question, but it doesn't wait for the answer:
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's ssh-ed25519 key fingerprint is:
ssh-ed25519 255 2e:65:6a:c8:cf:bf:b2:8b:9a:bd:6d:9f:11:5c:12:16
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)
Autostore key is on
Default SSH port to connect to is 7999
I'm trying to configure Mercurial for use with both a windows server (freeSSHd) and client (both command line and TortoiseHG). I'm using the most recent versions of everything... all downloaded in the past few days. Using public key auth, I have been able to get connected to the server and I'm able to use plink to execute "hg version" and get a response, but when I try to clone a repository from the ssh server the command appears to hang. Running with -v yields:
hg -v clone ssh://<username>#<server>//hg/repositoryA testRepositoryA
running "plink.exe -i "<path to private key file>" <username>#<server> "hg -R /hg/repositoryA serve --stdio""
with nothing more forthcoming. Running the hg serve command directly on the server yields an apparently responsive Mercurial server, but the clients do not seem to make any further requests.
Running "hg serve" in the repository directory and cloning over http works perfectly.
What should I be looking for to help debug this? Is there something the clients (hg and TortoiseHG) aren't sending to continue the request stream?
Additional Information:
If I change to an invalid repository on the target machine, the appropriate error is displayed, so it does appear that the remote hg is running and correctly evaluating the path.
Running with --debug and --traceback results in:
sending hello command
sending between command
It hangs here, until I CTRL-C
Traceback (most recent call last):
File "mercurial\dispatch.pyo", line 46, in _runcatch
File "mercurial\dispatch.pyo", line 452, in _dispatch
File "mercurial\dispatch.pyo", line 320, in runcommand
File "mercurial\dispatch.pyo", line 504, in _runcommand
File "mercurial\dispatch.pyo", line 457, in checkargs
File "mercurial\dispatch.pyo", line 451, in <lambda>
File "mercurial\util.pyo", line 402, in check
File "mercurial\commands.pyo", line 636, in clone
File "mercurial\hg.pyo", line 187, in clone
File "mercurial\hg.pyo", line 63, in repository
File "mercurial\sshrepo.pyo", line 51, in __init__
File "mercurial\sshrepo.pyo", line 73, in validate_repo
KeyboardInterrupt
interrupted!
Responding to Ryan: There does not appear to be any CPU usage or increasing memory usage on the server. It appears to be waiting for the client to send a request or something similar.
11/19/2009 : More information:
The problem is definitely in the freeSSHd/server side of the equation. Connecting to bitbucket over ssh with the same keyset works fine. Still working on this.
The solution that worked for me was disable the "Use new console engine" option which is inside the SSH tab. Another thing is the path. ssh://ssh_user#SSH_Server_Address:SSH_Port/Win_Drive_Letter:/Path_To_HG_Repository
A concrete example:
ssh://programmer#192.168.1.150:5522/D:/Repository/MyProyect/trunk
I currently use MercurialHG not the CLI. I hope that this help
JQ
The solution actually I got it from here
I got the same symptoms just now, although hg was a bit more helpful after Ctrl+C - apparently plink was waiting for me to say y/n to "save server to cache". Unfortunately hg couldn't pass my y/n to it interactively (nor tell me that plink printed something important...)
Solution:
plink to the host once and save server info to cache
add -batch to the plink command line so that next time this happens it aborts instead.
I also add my key to pageant so I don't need to type the password anywhere else.
Complete example of .hgrc file (Win+R, notepad %USERPROFILE%\.hgrc):
[ui]
ssh=C:\Path\To\plink.exe -C -batch -ssh -i C:\Path\To\My\putty-private-ssh-key.ppk
Another option would be to try the Cygwin versions of hg and ssh. You can log SSH problems in that version with the -e option; for instance, hg clone -e 'ssh -vvv' ssh://you#server/repo...
I ran into this same problem. Not sure how it relates to yours, but this is what worked for me.
First, I will explain my set up.
I have a repository on my live site mysite.com
I have a local repository on my local machine in a folder mysite.com
I have other repositories, so I add [ui] settings to /.hg/.hgrc file in each repository folder on my local machine instead of the Mercurial.ini file.
First, if you have already connected via Putty, save the session because Plink can use stored sessions. Use Pageant and add your key.
Try running plink from the command line to connect using the stored session. For example, I saved my session as "mysite" in Putty.
C:\>plink mysite
Using username "mysite".
Last login: Fri Feb 26 21:16:05 2010 from ca-xxx-xx-x-xxx.sta.host.net
←]0;mysite#server:~[mysite#server ~]$
If that is working, try the following in your .hgrc file
[path]
default = ssh://mysite#myhost
[ui]
username = RB <admin#mysite.com>
ssh=plink.exe -ssh -i mysite
Plink is set in my PATH, and since the mysite session was already stored in Putty, it knows what to look for.
I was trying to do a pull, so I was testing using:
hg pull --debug --traceback
Hope that helps.
Edit: Sorry, saw too late you were using tortoiseHG instead of putty. Hope it helps anyway.
In my case I was able to connect to my server once but the second time it failed.
I have the same setup and it worked perfectly...but only once. There is nothing in my stored sessions.
[ui]
ssh=C:\Path\To\plink.exe -C -batch -ssh -i C:\Path\To\My\putty-private-ssh-key.ppk
Perhaps it's the case that 'hg' isn't in the path. You can see from the command line that's being invoked that 'hg' is being run as 'hg', which means it has to be in the server's path. Try using the --remotecmd option to clone to give the full path to the hg executable on the server (good luck getting the windows quoting right).
It's possible that your plink hg version test works because it's launched as an interactive shell which gets a different path -- at least that frequently stymies people on unix.
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!
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.
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:
Enable ssh login on both computers (required)
Set up an ssh tunnel from the remote machine to your machine (required)
Set up an alias for the ssh tunnel (optional)
Set up an alias for TextWrangler on the remote machine (optional)
Set up ssh keys so you don't have to enter your password every time (optional)
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:
ssh -f -N -R 10022:localhost:22 [username on remote machine]#[remote machine hostname]
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:
alias open-tunnel='ssh -f -N -R 10022:localhost:22 [username on remote machine]#[remote machine hostname]'
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:
ssh -p 10022 [username on local machine]#localhost "edit sftp://[username on remote machine]#[remote machine hostname]//absolute/path/to/file.txt"
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:
function edit { if [[ ${1:0:1} = "/" ]]; then abs_path="$1"; else abs_path="`pwd`/$1"; fi; ssh -p 10022 [username on local machine]#localhost "edit sftp://[username on remote machine]#[remote machine hostname]/$abs_path"; }
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 run edit some/other/directory/file.txt, the following will be executed on your local machine:
edit sftp://[username on remote machine]#[remote machine hostname]//home/jdoe/some/directory/some/other/directory/file.txt
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/
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
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 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.
Minimal answer
You can use Applescript. So from the command line execute this:
osascript <<EOF
tell application "TextWrangler"
activate
open location {"sftp://myusername:#my.server:22222//home/username/.bashrc"}
end tell
EOF
Notes
Obviously you wouldn't want to type a here document on every invocation, so my suggestion would be to put this logic inside a regular shell script:
osascript <<EOF
tell application "TextWrangler"
activate
open location {"$1"}
end tell
EOF
Then invoke the script like this:
sh ~/bin/textwrangler.sh "sftp://myusername:#my.server:22222//home/username/.bashrc"
Specifying a host-qualified path can get tedious each time so either hardcode that in your script, or bind the script invocation to a keystroke via your shell. For bash:
bind '"\et":"sh ~/bin/textwrangler.sh \"sftp://myusername:#my.server:22222/\""'
Now you generate the majority of the command by pressing Alt-t