Skip to content

Commit 8b5ebab

Browse files
committed
feat(ssh): suport home dir shorthand(~)
suport home dir shorthand(~) Signed-off-by: mritd <[email protected]>
1 parent dd6cbeb commit 8b5ebab

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mmh/ssh.go

+10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package mmh
33
import (
44
"errors"
55
"io/ioutil"
6+
"strings"
67
"time"
78

9+
"github.com/mitchellh/go-homedir"
10+
811
"github.com/mritd/mmh/utils"
912

1013
"github.com/mritd/sshutils"
@@ -93,6 +96,13 @@ func (s *ServerConfig) authMethod() []ssh.AuthMethod {
9396

9497
// privateKeyFile return private key auth method
9598
func privateKeyFile(file, password string) (ssh.AuthMethod, error) {
99+
if strings.HasPrefix(file, "~") {
100+
home, err := homedir.Dir()
101+
if err != nil {
102+
return nil, err
103+
}
104+
file = strings.Replace(file, "~", home, 1)
105+
}
96106
buffer, err := ioutil.ReadFile(file)
97107
if err != nil {
98108
return nil, err

version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.4.0
1+
v1.4.1

0 commit comments

Comments
 (0)