sup icon indicating copy to clipboard operation
sup copied to clipboard

Use ~/.ssh/config or allow user to override key

Open aelsabbahy opened this issue 7 years ago • 16 comments

Awesome project!

Currently it seems ssh key is hardcoded to ~/.ssh/id_rsa or ~/.ssh/id_dsa.

  • The easy fix: Allow user to specify it on the command line sup -i ~/.ssh/some_key ..
  • The more complex fix: Honer settings in ~/.ssh/config

aelsabbahy avatar Jul 21 '16 22:07 aelsabbahy

Or use ssh-agent, so if you have configured your keys to be cached by ssh-add, theoretically it should work... at least in code there was preparation for that: // If there's a running SSH Agent, try to use its Private keys. sock, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")) if err == nil { agent := agent.NewClient(sock) signers, _ = agent.Signers() }

Not sure it works, didn't for me. I had the same problem, eventually I simply dedicated a different User to use sup to work-around it :)

tpaz avatar Aug 21 '16 18:08 tpaz

I think ssh-agent worked for me when I tried it.

Honoring .ssh/config allows for more complex things like setting the user.

aelsabbahy avatar Aug 21 '16 18:08 aelsabbahy

ssh-agent works, as long as $SSH_AUTH_SOCK env var is set correctly

otherwise, sup defaults to ~/.ssh/id_rsa and ~/.ssh/id_dsa --- we might want to parse more files from ~/.ssh directory (ssh does this by default)

VojtechVitek avatar Aug 22 '16 17:08 VojtechVitek

Parsing ~/.ssh/config is also doable - but personally, I don't have time for it. Feel free to take over and send us a PR :)

VojtechVitek avatar Aug 22 '16 17:08 VojtechVitek

+1 worked for me with ssh-agent as described above, eventually :) to add config file support - I will first have to gain more experience in Go :)

tpaz avatar Aug 24 '16 11:08 tpaz

is this going to happen? :)

guitmz avatar Aug 31 '17 13:08 guitmz

I opened a Bountysource bounty if anyone wants to take it on. :)

Bounty

jakewarren avatar Aug 31 '17 15:08 jakewarren

@jakewarren I have a starter solution to parse / honour ~/.ssh/config in https://github.com/pressly/sup/pull/105 . shouldn't be too much of an extension to handle different keys as well

pxue avatar Aug 31 '17 18:08 pxue

@pxue pls let me know if you want to add it to #105. I'll try my best to finally finish the review after it's done. (Sorry for the delay!)

VojtechVitek avatar Aug 31 '17 20:08 VojtechVitek

I suspect the global auth initialization code:

var initAuthMethodOnce sync.Once
var authMethod ssh.AuthMethod

must be changed to something like:

var authMethod map[string]ssh.AuthMethod

Do allow per-network configuration of keys?

I would prefer to specify the keys in the supfile instead of parsing the openssh configfile because I prefer to have the config in one place. I also think it is not feasible to map the openssh CertificateFile to sups networks in a consistent way.

I my pull request https://github.com/juergenhoetzel/sup/commit/74b4a4b193c0f8cc3db1bb5b85fc981bdedfbb41 I have relaxed the search for SSH-Keys: Use of id_" wildcard.

juergenhoetzel avatar Oct 29 '17 14:10 juergenhoetzel

FYI, #123 has been just merged. Sup now loads any private key matching ~/.ssh/id_* wildcard.

VojtechVitek avatar Jan 16 '18 21:01 VojtechVitek

#105 and #124 were merged too.

The only remaining part is actually using the custom IdentityFile. It doesn't work yet.

VojtechVitek avatar Jan 16 '18 23:01 VojtechVitek

~~I think comments (#) if the config ends with a comment and lines ending with whitespace in the ssh config file make sup hang~~

ah sup hangs because doesn't expect a host to have multiple aliases, which might be the case if using ~/.ssh. The parser lib also doesn't trim whitespace from the Port field, that should at least do since the port is always single Although sup also hangs when the last line in the config is a comment, have not checked if its related to the parser

untoreh avatar May 18 '18 14:05 untoreh

Also when using a config file a run command is actually run only on one host (?) this is weird

untoreh avatar May 18 '18 17:05 untoreh

Yeah, I just figured it out, Is this a bug, not looping through the hosts if it's pulling from SSH Config file

mj-ano avatar Sep 21 '18 18:09 mj-ano

For those who want to use it with custom keys, simple symlink worked for me:

$ cd ~/.ssh
$ ln -s mykey id_mykey
$ ln -s mykey.pub id_mykey.pub

muodov avatar May 02 '19 10:05 muodov