magit seems to open a new ssh connection for every command. This becomes very annoying especially when staging more chunks, which takes noticeable time to establish the connection for each chunk.
(from shell, I have persistent ssh connections enabled via ./ssh/config)
I am not sure whether this is a magit or a tramp thing.
But my question is:
How can I make magit re-use the ssh-connection?
EDIT:
The client is
tramp 2.3.5.26.2
GNU Emacs 26.1.91
debian (testing)
this is the tramp configuration
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
(setq tramp-default-method "ssh")
(setq tramp-inline-compress-start-size 1000000)
this is the relevant part of my .ssh/config
## generally re-use existing connections
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r#%h-%p
ControlPersist 600
Host myhost1
HostName 111.11.11.1
User myuser
ForwardX11 yes
ForwardX11Timeout 596h
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
ForwardAgent yes
SendEnv LC_*
ServerAliveInterval 300
The server is RHEL 7.6 (Maipo)
By default Tramp doesn't use the ControlMaster options defined in your SSH config file (see the Tramp FAQ):
Tramp overwrites ControlPath settings when initiating ssh sessions.
Tramp does this to fend off a stall if a master session opened outside
the Emacs session is no longer open.
The FAQ also shows how to configure the ControlMaster options for TRAMP:
(customize-set-variable
'tramp-ssh-controlmaster-options
(concat
"-o ControlPath=/tmp/ssh-ControlPath-%%r#%%h:%%p "
"-o ControlMaster=auto -o ControlPersist=yes"))
Alternatively, if you want to tell Tramp to use the customisations in your ~/.ssh/config file you need to change the tramp-use-ssh-controlmaster-options variable:
(customize-set-variable 'tramp-use-ssh-controlmaster-options nil)
Related
Earlier this week I tried ssh'ing into my lab machine (as I do very frequently) via tramp mode (ubuntu 14.04) and now it seems to not work out of the blue. I have tried checking all folder permissions, that ssh actually works (in terminal, even nested in emacs). However, it still will not connect me. I see the connection in my .ssh file so I am not sure what the issue is. Any ideas? This is killing my productivity since I would much rather tramp in vs git everything.
######### from C-x C-f ssh:user#host...etc (which has always worked in the past) #######
ssh: Could not resolve hostname ssh: Name or service not known
########## from *Messages buffer* #####################
Tramp: Opening connection for ssh using scp...
Tramp: Sending command `exec ssh -e none ssh'
Tramp: Waiting for prompts from remote shell
Tramp: Sending command `exec ssh -e none ssh'
Tramp: Opening connection for ssh using scp...done
byte-code: Process died
side note: I did start having pop-ups w/ system program problem detected but the ONLY thing in the /var/crash folder is a virtual box issue so I cant imagine that could be it. (Can I purge emacs and grab my config again and solve it that way?)
The error message clearly indicates that you are doing C-x C-f /ssh:user#host/path/to/file. A colon is missing after host. Pls open this like C-x C-f /ssh:user#host:/path/to/file.
My computer network is closed to ssh to external machines (outside the network) through port 22. I have a round about by tunneling ssh through http by employing cockscrew. I modified my config file in the following fashion
Host EXTERNAL-HOSTNAME
ControlMaster auto
ControlPath ~/.ssh/%r#%h:%p
ServerAliveCountMax=30
ServerAliveInterval=5
ProxyCommand corkscrew LOCAL-PROXYNAME PROXY-PORT-NO %h %p
How can I now use tramp to access the files in the remote cluster? The regular command /ssh:username#EXTERNAL-HOSTNAME fails to open the file.
UPDATE 1:
My proxy does not use the default 8080 port but a different port number. So using
/tunnel:PROXY-HOSTNAME PROXY-PORT-NO | ssh:USERNAME#EXTERNAL-HOSTNAME:~/
gave me the following error
Tramp: Opening connection for tunnel using scp... Tramp: Sending
command exec ssh -o
ControlPath=/var/folders/k5/r4f1q8j90y345rsz_9skc7y48q0jr6/T/tramp.15685eSq.%r#%h:%p
-o ControlMaster=auto -o ControlPersist=no -e none tunnel' Tramp: Waiting for prompts from remote shell... Tramp failed to connect. If
this happens repeatedly, try
M-x tramp-cleanup-this-connection' Tramp: Waiting for prompts from remote shell...failed Tramp: Opening connection for tunnel using
scp...failed Use M-x make-directory RET RET to create the directory
and its parents
Tramp: Checking `vc-registered' for /tunnel:PROXY-HOSTNAME
PROXY-PORT-NO | ssh:USERNAME#EXTERNAL-HOSTNAME:~/...failed Use M-x
make-directory RET RET to create the directory and its parents Mark
set
UPDATE 2:
It worked. The only problem was I was not entering the port-no correctly. Now I just used
/tunnel:PROXY-HOSTNAME#PROXY-PORT-NO|ssh:USERNAME#EXTERNAL-HOSTNAME:~/
and it worked.
I don't know corkscrew so I cannot answer for this. However, Tramp is able to tunnel http by its own. Try to open /tunnel:LOCAL-PROXYNAME|ssh:username#EXTERNAL-HOSTNAME. The proxy command shall be removed from your ssh config, of course.
I think this is very basic question in using tramp, but it doesn't work for me.
I have my ~/.ssh/config file that points to my amazon ec2 machine
Host amazon
Hostname xxxx.amazonaws.com
Port yyy
User me
IdentityFile ~/.ssh/ubuntu
ForwardAgent yes
I can easily do ssh amazon from my terminal and I go to amazon ec2 (so my config is right), but in emacs
I do:
C-x C-f /ssh1:amazon:
I always get this error
In Aquamacs:
Process *tramp/ssh1 amz* exited abnormally with code 255
In Emacs:
tramp: Opening connection at amz using ssh1...
tramp: Waiting for prompts from remote shell
tramp: Waiting 60s for prompt from remote shell
tramp-process-actions: Login failed
I also have other ssh configurations that they ssh to my virtual boxes on my local machine and they have the same problem.
I really appreciate any help.
One thing that's worth trying is using the sshx connection method. That makes tramp try to avoid any non-standard shell configuration on the remote host.
Like this:
C-x C-f /sshx:amazon:
The tramp method ssh1 forces ssh to be run in ssh v1 protocol mode with the parameter -1. ssh v1 has known weaknesses and is insecure. Hence a lot of sites disable the ssh v1 protocol.
You can verify this from the shell with ssh -1 me#xxxx.amazonaws.com.
Try other tramp connection methods like ssh, sftp or scpx. You can see all pre-configured connection methods with C-h v tramp-methods.
If Moritz Bunkus's answer doesn't solve the issue, then you can configure the verbosity of tramp's output with
M-x customize-variable RET tramp-verbose RET
In particular, level 6 is "sent and received strings" which might help you to determine whether the "Waiting for prompts from remote shell" is because it isn't receiving a prompt pattern that it recognises, or because of some more critical failure.
If it's simply receiving a prompt it doesn't recognise, then you might look at customizing the tramp-login-prompt-regexp or tramp-shell-prompt-pattern variables.
(Of course if your ssh agent is working correctly, then login prompts shouldn't be relevant.)
If you're running Emacs in Windows, then also see these Q&As:
Emacs: Tramp doesn't work
Using tramp with EmacsW32 and cygwin, possible?
Could somebody please help me setup Emacs Tramp to do a double hop?
I want to work on machine2.abc.def.edu to which I can connect only through machine1.abc.def.edu. My username is myname, on both machines same.
I've tried to add .emacs:
(add-to-list 'tramp-default-proxies-alist
'("\\`machine2\\.abc\\.def\\.edu\\'"
"\\`myname\\'"
"/ssh:machine1\\.abc\\.def\\.edu:"))
This is my best guess interpretation of what's in the manual. Then I do:
C-x C-f /ssh:machine2.abc.def.edu
or:
C-x C-f /ssh:rsuhada#machine2.abc.def.edu
But both give:
ssh: Could not resolve hostname ssh: nodename nor servname provided, or not known
Process *tramp/scpc ssh* exited abnormally with code 255
And my Aquamacs can't be quitted and have to killed from shell... There is a 2 years thread here with same question. I've tried the answer from there:
(add-to-list 'tramp-default-proxies-alist
'("machine2.abc.def.edu"
nil
"/ssh:myname#machine1.abc.def.edu:"))
With same results... also for all combinations I could come up with... Remote editing on machine1.abc.def.edu works fine, though.
The answer it to use the ssh_proxy command available in ssh_config. Documented here and here. Basically you create a config file in your ssh folder that you can write shortcuts in. One of your shortcuts is to use a proxy through another end point. All of your shortcuts work for any tool that uses ssh including git and emacs.
Host endpoint2
User myusername
HostName mysite.com
Port 3000
ProxyCommand ssh endpoint1 nc -w300 %h %p
Host endpoint1
User somename
HostName otherdomainorip.com
Port 6893
In this example running ssh endpoint2 will automatically hop through endpoint1.
Okay, let's try something different then, without opening a tunnel. How about the following in your .emacs file:
(add-to-list 'tramp-default-proxies-alist
'("\\`machine2\\'"
nil
"/ssh:%u#machine1.abc.def.edu:"))
This is different from the code you found in the forum post in two points:
it adds ticks around the target host
name (Emacs regexp syntax to avoid
matching partial names)
it uses only
the subdomain name in the target
host (you reported in a comment
below that you cannot ssh to
machine2 when you use the full
domain name)
Does that help when you try to access a file on machine2?
Set up an ssh tunnel from machine1 to machine2 (assuming that sshd runs on port 22 on machine2):
machine1.abc.def.edu> ssh -f -N -L 2222:localhost:22 machine2.abc.def.edu
Then either connect to machine2 from Emacs like this:
/ssh:machine1.abc.def.edu#2222
or add the following line to your .emacs:
(add-to-list 'tramp-default-proxies-alist
'("\\`machine2\\.abc\\.def\\.edu\\'" nil
"/tunnel:machine1.abc.def.edu#2222:"))
How can I edit files on my remote host using my local Emacs when I can access the remote host only through SSH with public key authentication? Tramp handles normal password logins pretty well but I can't figure out how to get it work with key pairs. I'm using unix/linux on both ends.
There is no TRAMP equivalent to ssh user#host -i private-key.pem. However, if you run the shell command ssh-add private-key.pem, then ssh (and thus TRAMP) will automatically use private-key.pem for authentication. Simply ssh user#host will work on the shell, and opening the file /user#host:~/filename.txt will work in emacs, without it prompting for a password.
I don't get your question as Tramp works perfectly well with public-key authenticated SSH connections.
For instance, assuming you have set the following config in ~/.ssh/config:
Host remotehost
User mylogin
Port 22
Hostname remotehost.fqdn
and assuming that you can run ssh remotehost correctly in a terminal, then you are able to open your remote file using TRAMP C-x C-f /remotehost:path/to/file
If you are on Windows you can use plink with tramp easily. You have to make sure the plink binary is in your path and have to customize the variable (M-x customize-option) tramp-default-method to plink which combined with pageant would get you what you want.
I let you read the putty home page how to configure pageant to add your key.
There is the method plinkx as well which use the profile name so when you do a :
C-x C-f /putty_profile:
It will get the putty_profile from your putty saved profile name.
If you are using Linux usually modern distros should have the gnome keyring (named as well seahorse) starting X with a global SSH agent. Example on my debian distro :
chmouel#lutece:~$ ps aux|grep ssh-agent
chmouel 2917 0.0 0.0 4904 552 ? Ss Aug30 0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /usr/bin/seahorse-agent --execute x-session-manager
if you do a ssh-add (making sure you have identity in your ~/.ssh properly configured) it should request for your password and identify for all your X session.
If it does not happen you probably have a problem somewhere else in your distro.