Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using tramp to connect to a remote emacs session

491 views
Skip to first unread message

Suvayu Ali

unread,
Sep 2, 2009, 7:06:02 PM9/2/09
to Emacs mailing list
Hi everyone,

I usually have to connect to my lab using tramp (tramp-default-method is
ssh) when I am working from home. Since I go back and forth a lot, I
have to start a session every time. Is it possible for me to run
emacs-server on my lab machine and connect to that using tramp from my
home? That would save me a lot of time (mostly annoyance though ;) ) in
starting a new session.

So far only reference I found was,

> Using emacsclient to make a new frame of a remote Emacs 22 on a local display
>
> ssh remote_host -f emacsclient --eval ‘”(make-frame-on-display \”$DISPLAY\”)”’

in the emacswiki[1]. Firstly I don't understand how this works, and
blindly copy-pasting this to the terminal didn't work either. Some help
would be greatly appreciated. :)

I am using,
remote machine: Ubuntu 9.04 with Emacs 23
local machine: Fedora 11 with Emacs 23

[1]http://www.emacswiki.org/emacs/EmacsClient#toc22

--
Suvayu

Open source is the future. It sets us free.


Peter Dyballa

unread,
Sep 3, 2009, 4:02:50 AM9/3/09
to Suvayu Ali, Emacs mailing list

Am 03.09.2009 um 01:06 schrieb Suvayu Ali:

> So far only reference I found was,
>
>> Using emacsclient to make a new frame of a remote Emacs 22 on a
>> local display
>> ssh remote_host -f emacsclient --eval ‘”(make-frame-on-display
>> \”$DISPLAY\”)”’
>
> in the emacswiki[1]. Firstly I don't understand how this works, and
> blindly copy-pasting this to the terminal didn't work either. Some
> help would be greatly appreciated. :)


Ssh opens a connection to remote_host and logs you in. The option -f
puts ssh into the background allowing to launch an X client. This one
is emacsclient, which is asked to evaluate some Lisp. This Lisp code
is make-frame-on-display, which makes GNU Emacs open (create) a new
frame on the specified screen as given by the environment variable
DISPLAY. On the remote host DISPLAY should point to your local screen
and its X server. So the remote GNU Emacs daemon or server will open
a frame as an X client of your local display's X server and
communicate with it via the SSH tunnel.


If this does not work you can start to debug ssh, but particularly
allow (trusted) X11 forwarding in the configuration of the SSH server
on the remote host. Your local X server must be informed to accept
connections from the remote host.

--
Greetings

Pete

UNIX is user friendly, it's just picky about who its friends are.

Michael Albinus

unread,
Sep 3, 2009, 9:08:46 AM9/3/09
to Suvayu Ali, Emacs mailing list
Suvayu Ali <fatkasuv...@gmail.com> writes:

> Hi everyone,

Hi,

> I usually have to connect to my lab using tramp (tramp-default-method is
> ssh) when I am working from home. Since I go back and forth a lot, I
> have to start a session every time. Is it possible for me to run
> emacs-server on my lab machine and connect to that using tramp from my
> home? That would save me a lot of time (mostly annoyance though ;) ) in
> starting a new session.

Since you are not the first one who has asked, I've just added the
following to the Tramp manual (Frequently Asked Questions):

---
* How can I use TRAMP to connect to a remote GNU Emacs session?

You can configure Emacs Client doing this. On the remote host,
you start the Emacs Server:

(require 'server)
(setq server-host (system-name)
server-use-tcp t)
(server-start)

Make sure, that the result of `(system-name)' can be resolved on
your local host; otherwise you might use a hard coded IP address.

The resulting file `~/.emacs.d/server/server' must be copied to
your local host, at the same location. You can call then the
Emacs Client from the command line:

emacsclient /ssh:user@host:/file/to/edit

`user' and `host' shall be related to your local host.
---

Best regards, Michael.


Suvayu Ali

unread,
Sep 3, 2009, 12:01:42 PM9/3/09
to Michael Albinus, Emacs mailing list
Hi Michael,

On Thursday 03 September 2009 06:08 AM, Michael Albinus wrote:
> Suvayu Ali<fatkasuv...@gmail.com> writes:
>
>> Hi everyone,
>
> Hi,
>
>> I usually have to connect to my lab using tramp (tramp-default-method is
>> ssh) when I am working from home. Since I go back and forth a lot, I
>> have to start a session every time. Is it possible for me to run
>> emacs-server on my lab machine and connect to that using tramp from my
>> home? That would save me a lot of time (mostly annoyance though ;) ) in
>> starting a new session.
>
> Since you are not the first one who has asked, I've just added the
> following to the Tramp manual (Frequently Asked Questions):
>

I think I went through that section but could not figure out how to get
the server file. That became clear as soon I saw your little code
snippet. :)

> ---
> * How can I use TRAMP to connect to a remote GNU Emacs session?
>
> You can configure Emacs Client doing this. On the remote host,
> you start the Emacs Server:
>
> (require 'server)
> (setq server-host (system-name)
> server-use-tcp t)
> (server-start)
>
> Make sure, that the result of `(system-name)' can be resolved on
> your local host; otherwise you might use a hard coded IP address.
>
> The resulting file `~/.emacs.d/server/server' must be copied to
> your local host, at the same location. You can call then the
> Emacs Client from the command line:
>
> emacsclient /ssh:user@host:/file/to/edit
>
> `user' and `host' shall be related to your local host.

Correct me if I go wrong, when I issue that command emacsclient tells
the remote server to connect with the localhost over tramp. It
determines where the remote server is from the server file.

My problem is my ISP at the local machine doesn't allow me to login to
it from outside. In other words I probably don't have a static ip. So
when I issue the command I get,

> $ emacsclient /ssh:us...@local.host:~/file
> emacsclient: connect: Connection refused
> emacsclient: connected to remote socket at xxx.xx.xxx.xx
> Waiting for Emacs...
>
> *ERROR*: Process died

And on the remote machine I get the following in the *Messages* buffer,

> Tramp: Opening connection for us...@local.host using ssh...
> Tramp: Waiting 60s for local shell to come up...
> Tramp: Sending command `ssh local.host -l user -q -e none && exit || exit'
> Tramp: Waiting for prompts from remote shell
> File error: Process died

So to summarize my problem is I can only connect one way, local.host to
remote machine, and hence tramp fails to work. Does this mean the only
way I will get this working is to get my ISP to give me a static ip?

Thanks for the help so far Michael. Much appreciated.

Suvayu Ali

unread,
Sep 3, 2009, 12:06:16 PM9/3/09
to Peter Dyballa, Emacs mailing list
Hi Peter,

Thanks for the very clear explanation Pete. :) I had a hunch it is
something like X-forwarding. I don't really like to do X-forwarding, the
interface is usually very unresponsive. I would rather go with `emacs -nw'.

Thanks for the reply though. ^_^

Anselm Helbig

unread,
Sep 3, 2009, 12:34:50 PM9/3/09
to
At Thu, 03 Sep 2009 09:06:16 -0700,

If you want to connect to a remote emacs but don't want to do X
forwarding, then you can do either

- start emacs with the --daemon option on the remote host; you can
now connect to the running emacs instance with `emacsclient -t'
which will give you an emacs terminal frame. Which will, of
course, work over ssh as well. You can still get a X frame if you
like by not using -t. This requires Emacs 23 to work.

- the obvious solution: use GNU screen or a similar tool (dtach,
tmux, ...), start your console mode emacs in there and reconnect
as necessary. Works with any version of emacs, obviously.

HTH,

Anselm


--
Anselm Helbig
mailto:anselm.helb...@googlemail.com

Benjamin Andresen

unread,
Sep 3, 2009, 1:50:01 PM9/3/09
to
Michael Albinus <michael...@gmx.de> writes:

> * How can I use TRAMP to connect to a remote GNU Emacs session?
>
> You can configure Emacs Client doing this. On the remote host,
> you start the Emacs Server:
>
> (require 'server)
> (setq server-host (system-name)
> server-use-tcp t)
> (server-start)
>
> Make sure, that the result of `(system-name)' can be resolved on
> your local host; otherwise you might use a hard coded IP address.
>
> The resulting file `~/.emacs.d/server/server' must be copied to
> your local host, at the same location. You can call then the
> Emacs Client from the command line:
>
> emacsclient /ssh:user@host:/file/to/edit
>
> `user' and `host' shall be related to your local host.

I don't quite get this. As I understand it the following happens:

Remote Emacs (R) has emacs running with the above server settings.
Local emacs (L) will copy the ~R/.emacs.d/server/server to
~L/.emacs.d/server/server

and then launch emacsclient -f server /ssh:user@L:/etc/localfile

But to do any editing, you still need to be at R (i.e. attached scree)
to see the /etc/localfile being opened. All the emacsclient line will do
is instruct R to open that file. After wards you then press C-x # on R to
close that connection.
(All L sees is "Waiting for Emacs..." until that happens.)

Why not ssh into R and just C-x C-f /ssh:user@L:/etc/localfile without
copying anything?

Therefor I don't see what you gain. You still need R to be able to
connect via ssh to L, which means it might possibly go trough a NAT.

What am I missing?

TIA,
benny

Suvayu Ali

unread,
Sep 3, 2009, 11:17:27 PM9/3/09
to Anselm Helbig, Emacs mailing list
Hi Anselm,

Sorry for going OT, I looked into screen after your post. Isn't it
almost the same as any terminal emulators available on GNU/Linux
systems? (xfce4-terminal, konsole, gnome-terminal ...) What are the
advantages offered by screen over a regular ssh session in one of these
terminal emulators?

Benjamin Andresen

unread,
Sep 3, 2009, 11:27:29 PM9/3/09
to
Suvayu Ali <fatkasuv...@gmail.com> writes:

> Sorry for going OT, I looked into screen after your post. Isn't it
> almost the same as any terminal emulators available on GNU/Linux
> systems? (xfce4-terminal, konsole, gnome-terminal ...) What are the
> advantages offered by screen over a regular ssh session in one of
> these terminal emulators?

screen complements a terminal emulator, because it does simultaneously
more and less than one.

From http://en.wikipedia.org/wiki/GNU_Screen

GNU Screen is a free terminal multiplexer that allows a user to access
multiple separate terminal sessions inside a single terminal window or
remote terminal session. It is useful for dealing with multiple programs
from the command line, and for separating programs from the shell that
started the program.


Features
Persistence

Similar to VNC, GNU Screen allows the user to start applications
from one computer, and then reconnect from a different computer
and continue using the same application without having to
restart it.


Multiple windows

Multiple terminal sessions can be created, each of which usually
runs a single application.


Session Sharing

Screen allows multiple computers to connect to the same session
at once, allowing collaboration between multiple users.


If that doesn't answer the question, install it and follow this guide:
http://www.kuro5hin.org/story/2004/3/9/16838/14935

HTH,
benny

Michael Albinus

unread,
Sep 4, 2009, 3:03:17 AM9/4/09
to Suvayu Ali, Emacs mailing list
Suvayu Ali <fatkasuv...@gmail.com> writes:

> Hi Michael,

Hi,

>> ---


>> * How can I use TRAMP to connect to a remote GNU Emacs session?
>>
>> You can configure Emacs Client doing this. On the remote host,
>> you start the Emacs Server:
>>
>> (require 'server)
>> (setq server-host (system-name)
>> server-use-tcp t)
>> (server-start)
>>
>> Make sure, that the result of `(system-name)' can be resolved on
>> your local host; otherwise you might use a hard coded IP address.
>>
>> The resulting file `~/.emacs.d/server/server' must be copied to
>> your local host, at the same location. You can call then the
>> Emacs Client from the command line:
>>
>> emacsclient /ssh:user@host:/file/to/edit
>>
>> `user' and `host' shall be related to your local host.
>

> Correct me if I go wrong, when I issue that command emacsclient tells
> the remote server to connect with the localhost over tramp. It
> determines where the remote server is from the server file.

Yes.

> My problem is my ISP at the local machine doesn't allow me to login to
> it from outside. In other words I probably don't have a static ip. So
> when I issue the command I get,
>
>> $ emacsclient /ssh:us...@local.host:~/file
>> emacsclient: connect: Connection refused
>> emacsclient: connected to remote socket at xxx.xx.xxx.xx
>> Waiting for Emacs...
>>
>> *ERROR*: Process died

So at least emacsclient was able to connect your remote server. Good.

> And on the remote machine I get the following in the *Messages* buffer,
>
>> Tramp: Opening connection for us...@local.host using ssh...
>> Tramp: Waiting 60s for local shell to come up...
>> Tramp: Sending command `ssh local.host -l user -q -e none && exit || exit'
>> Tramp: Waiting for prompts from remote shell
>> File error: Process died

That I do not catch. Are the messages exactly as you have written, or
did you exchange the real user and host name by "user" and "local.host"?

Note, that "user" shall be the user name you run your local host, and
"local.host" must be an FQDN of your host, or an IP address.

> So to summarize my problem is I can only connect one way, local.host to
> remote machine, and hence tramp fails to work. Does this mean the only
> way I will get this working is to get my ISP to give me a static ip?

You have mentioned two different explanations. Either your ISP does not
allow you to login from the outside. Then we could stop. But usually,
they don't forbid it.

If you have a dynamic IP address (the other possiblitiy), you could run

emacsclient /ssh:us...@1.2.3.4:/file/to/edit

"1.2.3.4" would be the IP address you are currently using. Because this
changes day by day, you might evaluate it every time in a script,
starting emacsclient.

The more simple solution is to register your local machine with dynamic
DNS. Let's say you have registered it at http://www.dyndns.com/, under
the name "suvayu.homelinux.org" (just as example). Then you could
connect via

emacsclient /ssh:us...@suvayu.homelinux.org:/file/to/edit

Another trap you could enter is your router configuration at home. You
must allow incoming connections at port 22 (for ssh), and it must be
forwarded to your local host.

> Thanks for the help so far Michael. Much appreciated.

Best regards, Michael.


Suvayu Ali

unread,
Sep 4, 2009, 7:05:09 AM9/4/09
to Michael Albinus, Emacs mailing list
Hi Michael,

On Friday 04 September 2009 12:03 AM, Michael Albinus wrote:
> Suvayu Ali<fatkasuv...@gmail.com> writes:
>

>> Correct me if I go wrong, when I issue that command emacsclient tells
>> the remote server to connect with the localhost over tramp. It
>> determines where the remote server is from the server file.
>
> Yes.
>
>> My problem is my ISP at the local machine doesn't allow me to login to
>> it from outside. In other words I probably don't have a static ip. So
>> when I issue the command I get,
>>
>>> $ emacsclient /ssh:us...@local.host:~/file
>>> emacsclient: connect: Connection refused
>>> emacsclient: connected to remote socket at xxx.xx.xxx.xx
>>> Waiting for Emacs...
>>>
>>> *ERROR*: Process died
>
> So at least emacsclient was able to connect your remote server. Good.
>
>> And on the remote machine I get the following in the *Messages* buffer,
>>
>>> Tramp: Opening connection for us...@local.host using ssh...
>>> Tramp: Waiting 60s for local shell to come up...

>>> Tramp: Sending command `ssh local.host -l user -q -e none&& exit || exit'


>>> Tramp: Waiting for prompts from remote shell
>>> File error: Process died
>
> That I do not catch. Are the messages exactly as you have written, or
> did you exchange the real user and host name by "user" and "local.host"?
>

My lab is a bit paranoid about security so I edited out the specifics
and put in generic names. :)

> Note, that "user" shall be the user name you run your local host, and
> "local.host" must be an FQDN of your host, or an IP address.
>

The host name for my localhost is limited to the local network. The
Siemens router from my ISP (Telus) probably implements some kind of NAT
(I'm not sure). So the outgoing connection worked, whereas the incoming
connection failed.

>> So to summarize my problem is I can only connect one way, local.host to
>> remote machine, and hence tramp fails to work. Does this mean the only
>> way I will get this working is to get my ISP to give me a static ip?
>
> You have mentioned two different explanations. Either your ISP does not
> allow you to login from the outside. Then we could stop. But usually,
> they don't forbid it.
>

I don't have a static IP, moreover from the outside I can only see my
ISP's servers not my home machine. Hence I can't login from the outside.

> If you have a dynamic IP address (the other possiblitiy), you could run
>
> emacsclient /ssh:us...@1.2.3.4:/file/to/edit
>
> "1.2.3.4" would be the IP address you are currently using. Because this
> changes day by day, you might evaluate it every time in a script,
> starting emacsclient.
>
> The more simple solution is to register your local machine with dynamic
> DNS. Let's say you have registered it at http://www.dyndns.com/, under
> the name "suvayu.homelinux.org" (just as example). Then you could
> connect via
>
> emacsclient /ssh:us...@suvayu.homelinux.org:/file/to/edit
>

This is very interesting. I had no idea such a service existed! I will
definitely look into this.

> Another trap you could enter is your router configuration at home. You
> must allow incoming connections at port 22 (for ssh), and it must be
> forwarded to your local host.
>

I can login to my router's admin interface, so that should not be
difficult to setup.

Thanks for your patience. :)

Suvayu Ali

unread,
Sep 4, 2009, 7:12:48 AM9/4/09
to help-gn...@gnu.org
The /etc/localfile is local to R not L. ssh-ing to R would mean either
X-forwarding or using `emacs -nw'. Whereas this way I get the whole gui
and since Tramp edits a localfile in /tmp I am independent on any
network issues until I actually do `C-x C-s' to save my edits.

> Therefor I don't see what you gain. You still need R to be able to
> connect via ssh to L, which means it might possibly go trough a NAT.
>
> What am I missing?
>
> TIA,
> benny

Suvayu Ali

unread,
Sep 4, 2009, 7:19:28 AM9/4/09
to help-gn...@gnu.org
Hi Benny,

On Thursday 03 September 2009 08:27 PM, Benjamin Andresen wrote:
> screen complements a terminal emulator, because it does simultaneously
> more and less than one.
>
> From http://en.wikipedia.org/wiki/GNU_Screen
>

I had gone through the wikipedia article and thought tabs in terminal
emulators solve my problems with ease.

> If that doesn't answer the question, install it and follow this guide:
> http://www.kuro5hin.org/story/2004/3/9/16838/14935
>

hank you for this link. I will definitely checkout screen seems like a
good way to be immune from hangups. :)

Michael Albinus

unread,
Sep 4, 2009, 7:37:53 AM9/4/09
to Suvayu Ali, Emacs mailing list
Suvayu Ali <fatkasuv...@gmail.com> writes:

> Hi Michael,

Hi,

> The host name for my localhost is limited to the local network. The

> Siemens router from my ISP (Telus) probably implements some kind of NAT
> (I'm not sure). So the outgoing connection worked, whereas the incoming
> connection failed.

When you have connected to the remote host, call "who":

slbpky:~> who
albinus tty7 2009-09-02 16:19 (:0)
albinus pts/0 2009-09-02 16:19 (localhost:10.0)
albinus pts/1 2009-09-04 08:29 (100.200.100.200)
albinus pts/2 2009-09-04 08:31 (localhost:12.0)

The string "100.200.100.200" I have used instead of my real values ...
This is the IP address your router is visible in the net. You can try to
reach it from your remote host via "ping 100.200.100.200".

If you have enabled NAT forwarding of port 22 in our router (Siemens
router shall allow this), you can even try "ssh us...@100.200.100.200".
You shall reach your local host from the remote one.

> I don't have a static IP, moreover from the outside I can only see my
> ISP's servers not my home machine. Hence I can't login from the outside.

I hope you see at least your router as described above.

>> The more simple solution is to register your local machine with dynamic
>> DNS. Let's say you have registered it at http://www.dyndns.com/, under
>> the name "suvayu.homelinux.org" (just as example). Then you could
>> connect via
>>
>> emacsclient /ssh:us...@suvayu.homelinux.org:/file/to/edit
>
> This is very interesting. I had no idea such a service existed! I will
> definitely look into this.

You shall register your router as dynamic DNS client (most routers offer
this), because this device is visible from outside, and not your local
host. And via NAT forwarding you reach the sshd daemon on your local
host.

> Thanks for your patience. :)

Best regards, Michael.


Suvayu Ali

unread,
Sep 4, 2009, 7:17:32 AM9/4/09
to help-gn...@gnu.org
Hi Benny,

I had gone through the wikipedia article and thought tabs in terminal
emulators solve my problems with ease.

On Thursday 03 September 2009 08:27 PM, Benjamin Andresen wrote:
>
> If that doesn't answer the question, install it and follow this guide:
> http://www.kuro5hin.org/story/2004/3/9/16838/14935
>

Thank you for this link. I will definitely checkout screen seems like a

good way to be immune from hangups. :)

--

Suvayu Ali

unread,
Sep 5, 2009, 1:29:01 AM9/5/09
to Emacs mailing list
Hi Michael,

On Friday 04 September 2009 04:37 AM, Michael Albinus wrote:
> Suvayu Ali<fatkasuv...@gmail.com> writes:
>

>> The host name for my localhost is limited to the local network. The
>> Siemens router from my ISP (Telus) probably implements some kind of NAT
>> (I'm not sure). So the outgoing connection worked, whereas the incoming
>> connection failed.
>
> When you have connected to the remote host, call "who":
>
> slbpky:~> who
> albinus tty7 2009-09-02 16:19 (:0)
> albinus pts/0 2009-09-02 16:19 (localhost:10.0)
> albinus pts/1 2009-09-04 08:29 (100.200.100.200)
> albinus pts/2 2009-09-04 08:31 (localhost:12.0)
>
> The string "100.200.100.200" I have used instead of my real values ...
> This is the IP address your router is visible in the net. You can try to
> reach it from your remote host via "ping 100.200.100.200".
>
> If you have enabled NAT forwarding of port 22 in our router (Siemens
> router shall allow this), you can even try "ssh us...@100.200.100.200".
> You shall reach your local host from the remote one.
>
>> I don't have a static IP, moreover from the outside I can only see my
>> ISP's servers not my home machine. Hence I can't login from the outside.
>
> I hope you see at least your router as described above.
>

Unfortunately I can't ping my router from the remote machine and get a
response. It seems my ISP is the culprit. Call to tech support didn't
help either. :( I will try posting on my distro's user list. This has
become way off-topic here.

Wish me luck. And thanks to all those who replied to the thread.

0 new messages