Skip to content

Commit

Permalink
fix: ssh connect failed with password
Browse files Browse the repository at this point in the history
  • Loading branch information
poneding committed Jul 12, 2024
1 parent 1da9316 commit fee66f6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ MacOS & Linux 安装,参考以下命令:

```bash
# MacOS
sudo wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.2/ssher_1.0.2_darwin_arm64 -O /user/local/bin/ssher && sudo chmod +x /user/local/bin/ssher
sudo wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.3/ssher_1.0.3_darwin_arm64 -O /user/local/bin/ssher && sudo chmod +x /user/local/bin/ssher

# Linux
sudo wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.2/ssher_1.0.2_linux_amd64 -O /user/local/bin/ssher && sudo chmod +x /user/local/bin/ssher
sudo wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.3/ssher_1.0.3_linux_amd64 -O /user/local/bin/ssher && sudo chmod +x /user/local/bin/ssher
```

> 注意:下载前确认你的系统是 `arm64` 还是 `amd64`,下载对应的二进制文件。
Expand All @@ -46,7 +46,7 @@ Windows 安装,参考以下步骤:

```bash
# 下载 .exe 文件
wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.2/ssher_1.0.2_windows_amd64.exe
wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.3/ssher_1.0.3_windows_amd64.exe
```

下载完成后,将 `ssher.exe` 文件路径添加到环境变量中,或者将其放到一个已经添加到环境变量的路径下。
Expand Down
6 changes: 3 additions & 3 deletions README_en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ MacOS & Linux installation, refer to the following commands:

```bash
# MacOS
sudo wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.2/ssher_1.0.2_darwin_arm64 -O /user/local/bin/ssher && sudo chmod +x /user/local/bin/ssher
sudo wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.3/ssher_1.0.3_darwin_arm64 -O /user/local/bin/ssher && sudo chmod +x /user/local/bin/ssher

# Linux
sudo wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.2/ssher_1.0.2_linux_amd64 -O /user/local/bin/ssher && sudo chmod +x /user/local/bin/ssher
sudo wget https://ghproxy.ketches.cn/https://github.com/poneding/ssher/releases/download/v1.0.3/ssher_1.0.3_linux_amd64 -O /user/local/bin/ssher && sudo chmod +x /user/local/bin/ssher
```

> Note: Before downloading, make sure your system is `arm64` or `amd64`, and download the corresponding binary file.
Expand All @@ -46,7 +46,7 @@ Download the `ssher.exe` file first:

```bash
# Download .exe file
wget https://github.com/poneding/ssher/releases/download/v1.0.2/ssher_1.0.2_windows_amd64.exe
wget https://github.com/poneding/ssher/releases/download/v1.0.3/ssher_1.0.3_windows_amd64.exe
```

Add the `ssher.exe` file path to the environment variable after download done, or put it in a path that has already been added to the environment variable.
Expand Down
2 changes: 1 addition & 1 deletion cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func upgradeByDownload(v string) {

targetFile := fmt.Sprintf("ssher_%s_%s_%s%s", strings.Trim(v, "v"), runtime.GOOS, runtime.GOARCH, ext)

// download from github release. eg: https://github.com/poneding/ssher/releases/download/v1.0.2/ssher_1.0.2_linux_amd64
// download from github release. eg: https://github.com/poneding/ssher/releases/download/v1.0.3/ssher_1.0.3_linux_amd64
r, err := http.Get(fmt.Sprintf("%s/download/%s/%s", GH_RELEASE_PROXY_ADDR_BASE, v, targetFile))
if err != nil || r.StatusCode != http.StatusOK {
fmt.Println("✗ Failed to download:", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

const version = "v1.0.2"
const version = "v1.0.3"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Expand Down
27 changes: 11 additions & 16 deletions internal/ssh/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"os"
"os/exec"
"os/signal"
"runtime"
"strconv"
"syscall"

Expand Down Expand Up @@ -48,20 +47,17 @@ func Connect(profile *Profile) {
defer func() { _ = ptmx.Close() }() // Best effort.

// Handle pty size.
if runtime.GOOS != "windows" {
//
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)
go func() {
for range ch {
if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
log.Printf("error resizing pty: %s", err)
}
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)
go func() {
for range ch {
if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
log.Printf("error resizing pty: %s", err)
}
}()
ch <- syscall.SIGWINCH // Initial resize.
defer func() { signal.Stop(ch); close(ch) }() // Cleanup signals when done.
}
}
}()
ch <- syscall.SIGWINCH // Initial resize.
defer func() { signal.Stop(ch); close(ch) }() // Cleanup signals when done.

// Set stdin in raw mode.
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
Expand Down Expand Up @@ -99,9 +95,8 @@ func Connect(profile *Profile) {
fmt.Println("✗ Failed to write password to pty:", err)
os.Exit(0)
}
break
}
break
}

_, _ = io.Copy(os.Stdout, ptmx)
}

0 comments on commit fee66f6

Please sign in to comment.