Running emacs in server mode so it's possible to connect from remote locations [duplicate] - emacs

This question already has answers here:
Using Emacs server and emacsclient on other machines as other users
(4 answers)
remote emacs client connects, but doesn't create new frame in terminal
(1 answer)
Closed 8 years ago.
Is it possible to run emacs in server mode so remote clients can connect from remote locations via network? I'm just looking for the way to run emacs on remote powerful server and edit buffers locally using emacsclient while running compile command remotelly. This looks much better approach then using ssh session. Should not depend on network latency.

I think the best approach is: http://www.emacswiki.org/emacs/TrampMode

Basing on my comment above I'd recommend the following workflow:
Retrieve the sources you work on to the local directory (via scp or git, whatever)
Introduce the required changed to the code
To compile the code on remote server specify a custom compile-command which will:
Push changed files back to the remote server. E.g.: scp -r my-sources/ user-name#example.net:my-sources or via git push remote my-dev-branch
Run the compilation command through ssh and show the output. E.g.: ssh user-name#example.net -C "cd ~/my-sourcesl; make && ./bin/compiled-app"
note: for smooth commands execution through ssh, there is should a configured key-based authentication.
The significant drawback here is that at least it might not run X11 applications correctly (or at all)

Related

Using Putty to SSH ignoring all warnings in Perl [duplicate]

This question already has answers here:
Putty won't cache the keys to access a server when run script in hudson
(11 answers)
Closed 3 years ago.
I'm writing a Perl script to SSH into remote linux and maci machines from a windows. For that I'm running plink (putty link) command using qx. The problem is that when I try to run the plink command it gives a prompt
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. ...... If you do not trust this host, press Return to abandon the
connection. Store key in cache? (y/n)
I have to automate the process of running a command remotely. So, I somehow want to bypass this warning.
I could think of two ways of doing this but don't know how to accomplish these
Somehow bypass this warning from putty itself through some command line options or other commands
Some Perl way of passing input to plink when prompted
Can anyone suggest how to do this either in one of above ways or some other solutions.
I solved it using pipes to pass Y to plink when prompted - echo Y | plink -ssh <user>#<host> -pw <password> <command>.
For more details refer to this answer. Also note the answer by #clay where he says
For internal servers, the blind echo y | ... trick is probably adequate (and super simple). However, for external servers accessed over the internet, it is much more secure to accept the server host key once rather than blindly accepting every time.
This was the case with me - I was using plink to ssh to internal servers.

remote emacs client connects, but doesn't create new frame in terminal

I configured and started an emacs server in TCP mode:
Added (setq server-host "10.16.184.33") and (setq server-use-tcp t) to .emacs
ran emacs --daemon
On the same host, running emacsclient -t brings up an emacs frame in the current terminal, and running emacsclient -c brings up a new graphical client frame, as expected.
On a different host, running emacsclient -t -f ~/.emacs.d/server/server appears to successfully connect to the remote emacs server, but no frame is created in the terminal:
$ emacsclient -t -f ~/.emacs.d/server/server
emacsclient: connected to remote socket at 10.16.184.33
At this point, emacsclient is running in the foreground, and a Ctrl-c stops it with a SIGTERM.
the value of the server-client variable shows that remote emacs client is connected:
server-clients's value is
(#<process server <10.16.184.33:52710>> #<process server <10.16.177.8:59460>>)
Things that I've checked:
versions of Emacs and emacsclient: all 24.3
when swapping which machines are the server and the remote client, the same problem occurs, except...
emacsclient prints an extra error message
emacsclient: connected to remote socket at 10.16.177.8
*ERROR*: Could not open file: /dev/pts/26
Any ideas of what else to check or configure?
There is nothing you could “check or configure”. You simply cannot use emacsclient remotely, because both processes share the frame, which does not work remotely for obvious reasons.
If a client connects to an Emacs server, it does not actually create the frame itself. Rather, it merely tells the server what kind of frame to create, i.e. whether a GUI frame or a terminal frame. The server then creates the frame based on the client's request and parameters.
Specifically, in case of a TTY client (i.e. emacsclient -t) the server attempts to create a frame on the client's TTY. Obviously this won't work if the server runs on a different system. TTYs are local and not remotely accessible.
FYI, the “TCP mode” of the Emacs server was never intended for remote access. It is simply a workaround for systems which do not support local Unix sockets, that is, Windows.
You don't even want to try and make it work, because it's horribly insecure. Being intended as local protocol, Emacs server does neither support traffic encryption nor authentication. By running a remotely accessible Emacs server, you allow any other system to execute arbitrary Emacs Lisp on your machine.
The right way to use Emacs remotely is SSH. Setup an SSH server on the remote system, then connect to the system via SSH and start emacsclient -t in the remote shell.

Emacs-Tramp: Not working properly

I'm trying to use Tramp/Emacs-23 in Ubuntu 12.04 in order to edit the remote host files. My remote host has two step authentication (RSA+Passwd). I use multiplexing through .ssh/config to ensure that tramp can directly connect to the remote shell without having to provide passwords.
My problem however is that I have 3 different remote hosts. When I try to connect to remote host through tramp without the initial multiplexing (through terminal), the TRAMP hangs with a message stating "Tramp: Waiting for prompts from remote shell". I used the below mentioned commands in .ssh/config to ensure the connection gets lost after a specified interval upon no prompt.
Host *
ServerAliveCountMax=30
ServerAliveInterval=5
However this doesn't seem to have any effect on the tramp connection. It will be of help if someone can help me in fixing this issue.
Sorry that your question has been left hanging so long.
I can offer a couple of things to try, use the tramp protocol sshx instead of ssh, it seems to cope better with most non-vanilla ssh connections.
e.g.
/sshx:user#host:path/filename
The other thing to try is adding your ssh key passphrase to the session at startup, run an ssh-agent on the machine, and connect to it at startup, then run ssh-add to enter the passphrase once.
As a side note, upgrade your Emacs to 24.3 there's a lot of new/great stuff in there since 23.x

Download file while in ssh mode?

I use to navigate my remote servers with ssh. Sometimes i would like to download a file to open in my computer.
But the only way i know how to do it is to open a new command line window and use scp from local to remote.
is there a way to do this directly from the ssh server?
like a command that know my current ip so can set up everything automatically?
(wonderful would also be to do the upload in such a way...)
There is no easy way to do it - I used ssh & scp many years the way you just described. But, you may configure ssh & scp in such a way that they don't require password each time, which is very comfortable! For this, you need:
generate keys by ssh-keygen - they can be also passphrase (= password) protected
copy the keys to remote machine to ~/.ssh/authorized_keys
And then, each time you start a session, you run ssh-agent and ssh-add. You just enter the password once. And then you can just run scp/ssh many times, from scripts, etc., without the need to enter the password each time!
I don't remember the exact way how to configure all this, but have a look at manpages of all those useful tools! Many things can be automatized by placing them into ~/.bash_profile or ~/.bashrc files.
I found this while trying to answer your question for myself:
https://askubuntu.com/a/13586/137980
Just install zssh and use Ctrl-# to go into file transfer mode.

Is it possible for Emacs to run a Matlab shell that is located on a remote server?

I would like to be able to use Matlab-mode (matlab.el) to run a matlab shell. The only problem is, Matlab is located on a remote host. Is this even possible? If so, please explain. I'm currently playing around with tramp but to no avail.
Thanks.
I just tried using the emacs matlab mode through ssh, no problem
had to make a script which loads matlab, couldn't just specify the command in matlab.el
so:
/home/second/remoteMatlab:
#!/bin/bash
ssh orac matlab -nodisplay
where orac is the host which has matlab. you can pass commands to ssh here. i use ssh config and key authentication so only need the hostname here
in matlab.el, find
(defcustom matlab-shell-command
and set to eg
(defcustom matlab-shell-command "/home/second/remoteMatlab"
I am not 100% sure what you are doing, but this seems possible. If
you use Tramp (or sshfs, my personal choice) to edit a script on a
remote machine, you will be able to run it on that remote machine. If
you have a *shell* buffer open, it can easily be ssh'd to that remote
machine. If you are doing something REPL-like where emacs sends input
to this buffer that's connected to a process over ssh, it should still
work. If it is communicating with a remote process over a socket, you
can use ssh forwarding to make the socket appear local.
Anyway, there is not much gap between local and remote, so this should
all work out.
Finally, to toe the (GNU) party line... have you tried Octave running locally?
#Yotham : I can't comment yet on earlier answers, but your problem (Script working, malab-shell command in emacs not) may be due to the fact that you didn't delete/rename your matlab.elc file?
This way emacs never gets to know of the change since it prefers .elc over .el files for speed.
Resolved the same issue for me.
cheers
tnt