Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit d0dc8ca

Browse files
committed
Set a default ssh key in the ssh-config file
1 parent fc863af commit d0dc8ca

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/cmd/kssh/kssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func runSSHWithKey(keyPath string, remainingArgs []string) {
291291
}
292292
if user != "" {
293293
useConfig = true
294-
err = kssh.CreateDefaultUserConfigFile()
294+
err = kssh.CreateDefaultUserConfigFile(keyPath)
295295
if err != nil {
296296
fmt.Printf("Failed to set default user: %v\n", err)
297297
os.Exit(1)

src/kssh/ssh.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func AddKeyToSSHAgent(keyPath string) error {
2121
var AlternateSSHConfigFile = shared.ExpandPathWithTilde("~/.ssh/kssh-config")
2222

2323
// Create an SSH config file that inherits from the default SSH config file but sets a default SSH user
24-
func CreateDefaultUserConfigFile() error {
24+
func CreateDefaultUserConfigFile(keyPath string) error {
2525
user, err := GetDefaultSSHUser()
2626
if err != nil {
2727
return err
@@ -43,10 +43,13 @@ func CreateDefaultUserConfigFile() error {
4343
f.Close()
4444
}
4545

46+
// This config file sets a default ssh user and a default ssh key. This ensures that kssh's signed key will be
47+
// attempted before any other keys in the ssh-agent
4648
config := fmt.Sprintf("# kssh config file to set a default SSH user\n"+
4749
"Include config\n"+
4850
"Host *\n"+
49-
" User %s\n", user)
51+
" User %s\n"+
52+
" IdentityFile %s\n", user, keyPath)
5053

5154
f, err := os.OpenFile(AlternateSSHConfigFile, os.O_CREATE|os.O_WRONLY, 0644)
5255
if err != nil {

0 commit comments

Comments
 (0)