Tramp hangs after sending password - emacs

I am trying to SSH using plink.exe in Emacs Tramp. I've downloaded the plink.exe which works in a normal terminal but when I use
C-x C-f
/gg88#afs1.njit.edu:/afs/cad/u/g/g/gg88/public_html/index.html
In the minibuffer,
Tramp: Waiting for prompts from remote shell also appears.
c:/Users/name/emacs-24.3/bin where plink.exe is located is in exec-path. My .emacs contains only these lines. But after checking exec-path does contain the directory plink.exe is in.
(require 'tramp)
(setq tramp-default-method "plink")
There is also no problem using M-x eshell, going to c:/Users/name/emacs-24.3/bin, and running
plink.exe gg88#afs1.njit.edu
What can I do next to get this working?
Edit
Got plink to be recognized by adding the path to plink directly to the PATH variable but still have the
Tramp: Waiting for prompts from remote shell also appears.
problem
Edit2 Messages buffer
Tramp: Opening connection for gg88#afs1.njit.edu using plink...
Tramp: Sending command `plink -l gg88 -ssh afs1.njit.edu && exit || exit'
Tramp: Waiting for prompts from remote shell
Tramp: Sending Password
Tramp: Waiting for prompts from remote shell [7 times]
Tramp: Sending command `plink -l gg88 -ssh afs1.njit.edu && exit || exit'
Tramp: Opening connection for gg88#afs1.njit.edu using plink...done
Quit [2 times]

First I have plink.exe in my ~/.emacs.d/bin
and then I wrap everything in a runemacs.bat file in my emacs-24 directory:
SET HOME=D:\\benoit
SET PATH=%PATH%;%HOME%\.emacs.d\bin
start %CD%\bin\runemacs.exe
And it works.
Sometimes emacs for windows / tramp / putty / whatever messes, so I run tramp-cleanup-all-connections to get a fresh start. tramp bundled with emacs 24.2 is OK, but the one with 24.3 is buggy so you may need to update it manually.

Related

Tramp: hangs with "found remote shell prompt", got run nil "/bin:/usr/bin" repeatedly in debug buffer

I tried to use Tramp on MacOS with the Emacs downloaded from http://emacsformacosx.com/ and the versions are: Emacs: 26.3 Tramp: 2.3.5.26.3
When I connect to a ubuntu server, Tramp always hang after showing "found remote shell prompt". I set verbose to 10 with the following command:
(setq tramp-verbose 10)
Then type Ctrl-g after it hangs. The following messages repeat forever in the debug buffer:
21:07:47.790498 tramp-get-connection-property (7) # check-remote-echo nil
21:07:47.790591 tramp-get-connection-property (7) # check-remote-echo nil
21:07:48.794171 tramp-accept-process-output (10) # *tramp/ssh local#homes.local* run nil
"/bin:/usr/bin"
tramp_exit_status 0
I tried different Linux hosts but got the same error. I have set up my ssh key so I can ssh without inputting a password. How do I debug further to make Tramp work?
Thanks Michael Albinus's help through the tramp-devel#gnu.org I have found out what's wrong.
First I should add [[ $TERM == "dumb" ]] && PS1='$ ' && return in the .profile of the remote shell to make the prompt recognizable.
Then I need to disable .emacs by using emacs -Q --eval '(setq tramp-verbose 10)' and found that tramp works for me fine. This means my .emacs is wrong.
After bisecting I found the problem is due to a too-old AucTeX package I loaded.

emacs error in tramp mode

I have setup tramp mode with emacs, have been working using that mode for awhile, recently I start getting following error where I am unable to open any files.
Loading /etc/emacs/site-start.d/50sml-mode.el (source)...done [3 times]
For information about GNU Emacs and the GNU system, type C-h C-a.
Tramp: Opening connection for toolserver using scp...
Tramp: Sending command `exec ssh -e none toolserver'
Tramp: Waiting for prompts from remote shell
Tramp: Sending command `exec ssh -e none toolserver'
Tramp: Found remote shell prompt on `toolserver'
Tramp: Opening connection for toolserver using scp...done
byte-code: Couldn't find exit status of `test -e /home/FILE_NAME.py'
I have re-name the actual file to FILE_NAME.py
Actions taken:
I deleted the .tramp_history file but that didn't fix the problem.
try using the scpx or sshx protocol instead.
try (setq tramp-verbose 6) and check the output buffer to see what's really happening (C-h v tramp-verbose to see the levels), then proceed from there.
Sometimes, it's because my ssh-agent is dead. Restarting it solves the problem.
Sometimes it's because TRAMP still thinks the connection is somewhat usable when it's not. When this happen, I do M-x ibuffer * * D RET to kill all the TRAMP buffers so it starts over.
If none of this works, try to use latest TRAMP from melpa or to reinstall it. TRAMP works pretty fine out of the box, maybe you tweaked something that broke it?

How to kill a remote process without killing the shell (C-c C-c also kills the shell...)

Assume you work on a remote server from a local emacs shell (started with M-x shell). If you execute a process which takes too long (for example an ls in a directory with a huge amount of files), you would like to stop that process (in the terminal one would use control-c). I tried C-c C-c but that kills the whole shell... How can I only kill the running process on the remote server and not the whole shell?
Update
Step-by-step:
1) M-x shell (execute on local machine)
2) ssh mylogin#myremotemachine.foo.bar (execute on local machine)
3) sleep 60 (execute on remote machine)
4) C-c C-c (execute in the current shell)
=> instead of still being on the remote host and just the sleep command being killed, the whole remote connection is closed and you are on your local machine again.
When I follow the steps you listed, I find myself back at the remote shell prompt. I'm using Emacs 23.1.1.
I find that typing C-q C-c RET also interrupts the remote process, again leaving me at the remote shell prompt. You might try that as an alternate approach.
It is unclear to me if you want to kill the command from within emacs, but you could alternately open another connection or window (if you are using screen or tmux) and perform the standard
ps aux | grep hungprocess
and then
kill hungprocess_pid
For some reason I kept thinking that such a method wouldn't work and that I'd end up taking down emacs as well. I have used such a method multiple times when I haven't set up my gpg pinentry agent when opening a gpg encrypted file in emacs. Emacs/gpg will try to spawn a GUI and therefore hangs emacs, waiting for input in the GUI when I am remotely ssh'ed in.

Emacs: Tramp doesn't work

I tried to open a remote file via Emacs via Tramp.
(require 'tramp)
(setq tramp-default-method "ssh")
I get a message from Emacs
Tramp: Waiting for prompts from remote shell
Emacs hung and did not respond to any action after that
Emacs was installed on Windows; the remote file was on a Linux machine.
If the account you're connecting to uses some weird fancy shell prompt, then there is a good chance that this is what makes tramp trip.
Log in as root, then enter
PS1="> "
(that's a normal, standard shell (ZSH, BASH, younameit) prompt, one that tramp will understand)
then switch to the user account, and launch emacs -q (to make sure that your .emacs is not causing this mess) and try to C-x C-f /sudo:root#localhost:/etc/hosts and see what's what.
You can (not recommended) also customize the regexp that defines what tramp expects :
M-x customize-variable RET tramp-terminal-prompt-regexp
My approach :
Make sure the variable tramp-terminal-type is set to "dumb"
M-x customize-variable RET tramp-terminal-type
Test that in your .*shrc and serve the correct prompt :
case "$TERM" in
"dumb")
PS1="> "
;;
xterm*|rxvt*|eterm*|screen*)
PS1="my fancy multi-line \n prompt > "
;;
*)
PS1="> "
;;
esac
Your Windows ssh client is the key here, and the 'ssh' Tramp method is almost certainly wrong.
If you're using Cygwin, then you need to use the 'sshx' method, and you probably need to use ssh-agent to handle authentication. Details are here:
Using tramp with EmacsW32 and cygwin, possible?
I imagine the same applies to any stand-alone ssh client which does not require a full Cygwin installation, but does use the Cygwin DLLs. (I mention this, because I'm pretty sure I remember seeing such a thing.)
If you're using PuTTY then you want the 'plink' method, as Alex Ott pointed out. If the Wiki doesn't suffice, a search here will probably turn up solutions for configuring that approach.
Other alternatives I can suggest are:
Use the Cygwin-native Emacs. That will be slower than NTEmacs, but Tramp seems to work well with the 'ssh' method, and password-prompting works as well.
Host a Linux VM on your Windows box, and run Emacs on that. That's a fairly large hoop to jump through, but it's my preferred way of using Tramp when working in Windows.
Well, this is a defect of tramp.
The real solution is to prevent loading .bashrc when tramp is used. (because now it is PS1, but it can be PATH, or any other thing that your .bashrc will do that will displease tramp...).
This can be done by asking ssh to set an environment variable, and testing it in .bashrc:
Add this to ~/.emacs:
(require 'tramp-sh nil t)
(setf tramp-ssh-controlmaster-options (concat "-o SendEnv TRAMP=yes " tramp-ssh-controlmaster-options))
and that at the beginning of ~/.bashrc:
if [ ! -z ${TRAMP-x} ] ; then
return
fi
Another default of tramp is that it doesn't have a variable to pass random arguments to the ssh command, we have to piggy-back on tramp-ssh-controlmaster-options.
Had you checked Emacs wiki for solution? ssh is in PATH? It's also recommended to use plink on MS Windows - see section "Inline methods" in Tramp documentation
If the problem is your fancy custom prompt in the remote shell, an easy workaround is to add to your .bashrc or equivalent:
if [[ $TERM == "dumb" ]]; then
export PS1="$ "
fi
After you define your PS1.
Note: the credit goes to ChasingLogic as this is their suggestion in this thread.
By the way -- if You need tramp to sudo -- You can actually sudo without tramp using sudoedit.
Currently I'm using this bash function:
erf () { SUDO_EDITOR="emacsclient -a emacs" sudoedit $#; }

Emacs server file path

I'm using Aquamacs and started the emacs server with M-x server-start. My emacsclient connects just fine. However, when I start another ssh session (on the same pc) it cannot locate my socket-name / server file. It's not in ~/.emacs.d/server/server where I would expect it.
How can I find out which server-file / socket-name the emacs server is currently using?
This is my working configuration:
.emacs
(setq server-socket-dir "~/.emacs.d/server")
(server-start)
em.sh
location="/`whoami`#`hostname`:$(readlink -f $1)"
ssh <YOU#LOCAL-WORKSTATION> emacsclient -n -s '~/.emacs.d/server/server' $location
The variable server-socket-dir (atleast on GNU Emacs) is what holds the location of the socket. The socket file in my case is simply called server.
It's in $TMPDIR/emacsXXX/server where XXX is a number that depends on the version of Aquamacs you're running
This should also fix your problem without needing to manually delete the file.
M-x server-force-delete