{"id":13490616,"url":"https://github.com/clarkwang/passh","last_synced_at":"2025-04-21T18:53:24.904Z","repository":{"id":52968586,"uuid":"92049612","full_name":"clarkwang/passh","owner":"clarkwang","description":"𝐬𝐬𝐡𝐩𝐚𝐬𝐬 is 𝒃𝒓𝒐𝒌𝒆𝒏 by design","archived":false,"fork":false,"pushed_at":"2023-12-31T14:11:19.000Z","size":69,"stargazers_count":228,"open_issues_count":4,"forks_count":37,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-20T01:08:14.045Z","etag":null,"topics":["automation","ssh","sshpass"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clarkwang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-05-22T12:11:32.000Z","updated_at":"2025-04-10T14:11:42.000Z","dependencies_parsed_at":"2023-12-26T07:56:15.017Z","dependency_job_id":null,"html_url":"https://github.com/clarkwang/passh","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkwang%2Fpassh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkwang%2Fpassh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkwang%2Fpassh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarkwang%2Fpassh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clarkwang","download_url":"https://codeload.github.com/clarkwang/passh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249834787,"owners_count":21331989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","ssh","sshpass"],"created_at":"2024-07-31T19:00:49.491Z","updated_at":"2025-04-20T01:08:42.797Z","avatar_url":"https://github.com/clarkwang.png","language":"C","readme":"# passh\n\n**NOTE:** The pty related code is stolen from the [APUE book][apue].\n\n  [apue]: http://www.apuebook.com/\n\n## compile\n\n    $ cc -o passh passh.c\n    $ cp -v passh /usr/bin/\n    $ passh -h\n\n## usage \n\n```\nUsage: passh [OPTION]... COMMAND...\n\n  -c \u003cN\u003e          Send at most \u003cN\u003e passwords (0 means infinite. Default: 0)\n  -C              Exit if prompted for the \u003cN+1\u003eth password\n  -h              Help\n  -i              Case insensitive for password prompt matching\n  -n              Nohup the child (e.g. used for `ssh -f')\n  -p \u003cpassword\u003e   The password (Default: `password')\n  -p env:\u003cvar\u003e    Read password from env var\n  -p file:\u003cfile\u003e  Read password from file\n  -P \u003cprompt\u003e     Regexp (BRE) for the password prompt\n                  (Default: `[Pp]assword: \\{0,1\\}$')\n  -l \u003cfile\u003e       Save data written to the pty\n  -L \u003cfile\u003e       Save data read from the pty\n  -t \u003ctimeout\u003e    Timeout waiting for next password prompt\n                  (0 means no timeout. Default: 0)\n  -T              Exit if timed out waiting for password prompt\n  -y              Auto answer `(yes/no)?' questions\n\nReport bugs to Clark Wang \u003cdearvoid@gmail.com\u003e\n```\n\n## supported platforms\n\nTested on:\n\n* OpenWRT 15.05.1, ramips/mt7620 (on [Newifi Mini, or Lenovo Y1 v1][newifi])\n* Debian Linux 8, x86_64 (Jessie)\n* macOS 10.12 (Sierra)\n* Cygwin, x86_64 (on Windows 7)\n* FreeBSD 11.1, x86_64\n* AIX 7.2, ppc64le (added in [issue #7](https://github.com/clarkwang/passh/issues/7))\n\n  [newifi]: https://wiki.openwrt.org/toh/lenovo/lenovo_y1_v1\n\n## why i wrote passh\n\n1. I got a `Newifi Mini` router and installed `OpenWRT` on it. I want the router to be my `SOCKS` proxy so I run `ssh -D 8888 user@host` automatically at boot time but the SSH server only supports password auth. On Linux I would use `Expect` to automate `ssh` but `OpenWRT` does not install `Expect` by default and my router does not have enough storage for the extra `Tcl` and `Expect` packages.\n\n1. Then I tried [`sshpass`][sshpass] but `sshpass` seems more like a nice hack and it's *broken* by design. See following example on a Linux system:\n\n        $ tty\n        /dev/pts/18                                      // now we're on pts/18\n        $ sshpass bash --norc\n        bash: cannot set terminal process group (-1): Inappropriate ioctl for device\n        bash: no job control in this shell\n        bash-4.4# tty\n        /dev/pts/18                                      // the bash's stdin is also connected to pts/18\n        bash-4.4# ps p $$\n           PID TTY      STAT   TIME COMMAND\n         37151 pts/36   Ss+    0:00 bash --norc          // but the controlling terminal is pts/36\n        bash-4.4# ps t pts/36\n           PID TTY      STAT   TIME COMMAND\n         37151 pts/36   Ss+    0:00 bash --norc\n         37154 pts/36   R+     0:00 ps t pts/36\n        bash-4.4#\n        \n     Now let's try `passh`:\n \n        $ tty\n        /dev/pts/18                                      // now we're on pts/18\n        $ passh bash --norc\n        bash-4.4# tty\n        /dev/pts/36                                      // the bash's stdin is connected to the new pts/36\n        bash-4.4# ps p $$\n           PID TTY      STAT   TIME COMMAND\n         37159 pts/36   Ss     0:00 bash --norc          // pts/36 is its controlling terminal\n        bash-4.4# ps t pts/36\n           PID TTY      STAT   TIME COMMAND\n         37159 pts/36   Ss     0:00 bash --norc\n         37162 pts/36   R+     0:00 ps t pts/36\n        bash-4.4#\n\n    See [sshpass-broken.md](sshpass-broken.md) for more *sshpass is broken* examples.\n\n  [sshpass]: https://sourceforge.net/projects/sshpass/\n\n## auto answer questions\n\nYou can use `passh` for more than just inputting the passwords. For example, you could use this to both enter the password and answer yes to the question `Proceed with propagating updates` with the `unison` bidirecional sync tool:\n1. `passh -P 'Proceed with propagating updates' -p y passh -P '[Pp]assword: \\{0,1\\}$' -p password unison ...` \n\n`unison` has the builtin option called `-batch` to answer yes to this question `Proceed with propagating updates`, however that option also implies to ignore conflicts and fail silently. Then, using `passh` to answer `y` to the input question `Proceed with propagating updates` allows you to automate the process when there is no conflicts, because when there are conflicts the first question would be to chose which file should be synced.\n\n## examples\n\n1. `sshpass` is *better* in its own way.\n\n    For example, you can use `rsync` + `sshpass` like this:\n    \n        $ rsync -e 'sshpass -p password ssh' file user@host:/dir\n        \n    But with `passh` you have to:\n    \n        $ passh -p password rsync -e ssh file user@host:/dir\n        \n    Another example, with `sshpass` you can:\n    \n        $ echo date | sshpass -p password ssh user@host bash\n        \n    But with `passh` you have to:\n    \n        $ passh -p password bash -c 'echo date | ssh user@host bash'\n        \n1. Start SSH SOCKS proxy in background\n\n        $ passh -n -p password ssh -D 7070 -N -n -f user@host\n    \n    Here `-n` is required or `ssh -f` would not work. (I believe the bug is in OpenSSH though.)\n    \n1. Login to a remote server\n\n        $ passh -p password ssh user@host\n    \n1. Run a command on remote server\n\n        $ passh -p password ssh user@host date\n        \n1. Share a remote server with others and want to use your local `bashrc`?\n\n        $ passh -p password scp /local/bashrc user@host:/tmp/tmp.cAE8Kv\n        $ passh -p password ssh -t user@host bash --rc /tmp/tmp.cAE8Kv\n        \n1. Or just for fun\n\n        $ passh bash\n        $ passh vim\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarkwang%2Fpassh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclarkwang%2Fpassh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarkwang%2Fpassh/lists"}