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

Commit 3092a35

Browse files
authored
Merge pull request #22 from keybase/david/scp-rsync-info
Add information on how to use scp and rsync with kssh and default users
2 parents 52b3a1e + fc15e81 commit 3092a35

2 files changed

Lines changed: 63 additions & 6 deletions

File tree

docs/troubleshooting.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,42 @@ ssh-keygen \
6060
```
6161

6262
You can then use the signed SSH key to SSH via `ssh -i /path/to/key.pub user@server`.
63+
64+
## Default Users and kssh --provision
65+
66+
Default users are implemented using a custom SSH config file that inherits from the default one. This means that if you
67+
run:
68+
69+
```bash
70+
kssh --set-default-user developer
71+
kssh --provision
72+
scp foo server:~/
73+
```
74+
75+
It will not use the default user. There are two ways to work around this. If you do not need the default user to be kssh
76+
specific (eg if kssh is your primary way of accessing certain servers), then you can simply configure this default user
77+
globally by adding the below lines to `~/.ssh/config`
78+
79+
```bash
80+
Host *
81+
User developer
82+
```
83+
84+
If you do not want to do this, you can run scp with the kssh specific config file via:
85+
86+
```bash
87+
scp -F ~/.ssh/kssh-config foo server:~/
88+
```
89+
90+
Or analogously for rsync:
91+
92+
```bash
93+
rsync -e "ssh -F $HOME/.ssh/kssh-config" foo server:~/
94+
```
95+
96+
It may be useful to define aliases in your bashrc to simplify this:
97+
98+
```bash
99+
alias kscp='kssh --provision && scp -F ~/.ssh/kssh-config'
100+
alias krsync='kssh --provision && rsync -e "ssh -F $HOME/.ssh/kssh-config"'
101+
```

src/cmd/kssh/kssh.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,30 @@ func doAction(action Action, keyPath string, remainingArgs []string) {
5252
if action == SSH {
5353
runSSHWithKey(keyPath, remainingArgs)
5454
} else if action == Provision {
55-
err := kssh.AddKeyToSSHAgent(keyPath)
56-
if err != nil {
57-
fmt.Printf("%v\n", err)
58-
os.Exit(1)
59-
}
60-
fmt.Printf("Provisioned new SSH key at %s\n", keyPath)
55+
provision(keyPath)
56+
}
57+
}
58+
59+
func provision(keyPath string) {
60+
err := kssh.AddKeyToSSHAgent(keyPath)
61+
if err != nil {
62+
fmt.Printf("%v\n", err)
63+
os.Exit(1)
64+
}
65+
user, err := kssh.GetDefaultSSHUser()
66+
if err != nil {
67+
fmt.Printf("Failed to retrieve default SSH user: %v\n", err)
68+
os.Exit(1)
69+
}
70+
err = kssh.CreateDefaultUserConfigFile(keyPath)
71+
if err != nil {
72+
fmt.Printf("Failed to create the ssh config file for the default user: %v\n", err)
73+
os.Exit(1)
74+
}
75+
fmt.Printf("Provisioned new SSH key at %s\n", keyPath)
76+
if user != "" {
77+
fmt.Println("See docs/troubleshooting.md for information on configuring scp, rsync, etc to " +
78+
"use the configured kssh default user")
6179
}
6280
}
6381

0 commit comments

Comments
 (0)