Giter Club home page Giter Club logo

passh's Introduction

passh

NOTE: The pty related code is stolen from the APUE book.

compile

$ cc -o passh passh.c
$ cp -v passh /usr/bin/
$ passh -h

usage

Usage: passh [OPTION]... COMMAND...

  -c <N>          Send at most <N> passwords (0 means infinite. Default: 0)
  -C              Exit if prompted for the <N+1>th password
  -h              Help
  -i              Case insensitive for password prompt matching
  -n              Nohup the child (e.g. used for `ssh -f')
  -p <password>   The password (Default: `password')
  -p env:<var>    Read password from env var
  -p file:<file>  Read password from file
  -P <prompt>     Regexp (BRE) for the password prompt
                  (Default: `[Pp]assword: \{0,1\}$')
  -l <file>       Save data written to the pty
  -L <file>       Save data read from the pty
  -t <timeout>    Timeout waiting for next password prompt
                  (0 means no timeout. Default: 0)
  -T              Exit if timed out waiting for password prompt
  -y              Auto answer `(yes/no)?' questions

Report bugs to Clark Wang <[email protected]>

supported platforms

Tested on:

  • OpenWRT 15.05.1, ramips/mt7620 (on Newifi Mini, or Lenovo Y1 v1)
  • Debian Linux 8, x86_64 (Jessie)
  • macOS 10.12 (Sierra)
  • Cygwin, x86_64 (on Windows 7)
  • FreeBSD 11.1, x86_64
  • AIX 7.2, ppc64le (added in issue #7)

why i wrote passh

  1. 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.

  2. Then I tried sshpass but sshpass seems more like a nice hack and it's broken by design. See following example on a Linux system:

     $ tty
     /dev/pts/18                                      // now we're on pts/18
     $ sshpass bash --norc
     bash: cannot set terminal process group (-1): Inappropriate ioctl for device
     bash: no job control in this shell
     bash-4.4# tty
     /dev/pts/18                                      // the bash's stdin is also connected to pts/18
     bash-4.4# ps p $$
        PID TTY      STAT   TIME COMMAND
      37151 pts/36   Ss+    0:00 bash --norc          // but the controlling terminal is pts/36
     bash-4.4# ps t pts/36
        PID TTY      STAT   TIME COMMAND
      37151 pts/36   Ss+    0:00 bash --norc
      37154 pts/36   R+     0:00 ps t pts/36
     bash-4.4#
    

    Now let's try passh:

     $ tty
     /dev/pts/18                                      // now we're on pts/18
     $ passh bash --norc
     bash-4.4# tty
     /dev/pts/36                                      // the bash's stdin is connected to the new pts/36
     bash-4.4# ps p $$
        PID TTY      STAT   TIME COMMAND
      37159 pts/36   Ss     0:00 bash --norc          // pts/36 is its controlling terminal
     bash-4.4# ps t pts/36
        PID TTY      STAT   TIME COMMAND
      37159 pts/36   Ss     0:00 bash --norc
      37162 pts/36   R+     0:00 ps t pts/36
     bash-4.4#
    

    See sshpass-broken.md for more sshpass is broken examples.

auto answer questions

You 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:

  1. passh -P 'Proceed with propagating updates' -p y passh -P '[Pp]assword: \{0,1\}$' -p password unison ...

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.

examples

  1. sshpass is better in its own way.

    For example, you can use rsync + sshpass like this:

     $ rsync -e 'sshpass -p password ssh' file user@host:/dir
    

    But with passh you have to:

     $ passh -p password rsync -e ssh file user@host:/dir
    

    Another example, with sshpass you can:

     $ echo date | sshpass -p password ssh user@host bash
    

    But with passh you have to:

     $ passh -p password bash -c 'echo date | ssh user@host bash'
    
  2. Start SSH SOCKS proxy in background

     $ passh -n -p password ssh -D 7070 -N -n -f user@host
    

    Here -n is required or ssh -f would not work. (I believe the bug is in OpenSSH though.)

  3. Login to a remote server

     $ passh -p password ssh user@host
    
  4. Run a command on remote server

     $ passh -p password ssh user@host date
    
  5. Share a remote server with others and want to use your local bashrc?

     $ passh -p password scp /local/bashrc user@host:/tmp/tmp.cAE8Kv
     $ passh -p password ssh -t user@host bash --rc /tmp/tmp.cAE8Kv
    
  6. Or just for fun

     $ passh bash
     $ passh vim
    

passh's People

Contributors

clarkwang avatar evandrocoan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

passh's Issues

Need help in compiling for openwrt

Hi,
Can someone help me with compiling passh for openwrt? (I never ever compiled something :-) )
And need passh for my micro wrt router (GL-AR750S)
Iam on OpenWrt 18.06.1, r7258-5eb055306f and installed "make" but it can't find "cc command".

Which is the best method for newbies to compile?

Maybe it's pssible that you can create a "compiled release" here??

best regards

AIX compile error

I tried compiling passh on AIX 7.2.0.0 with gcc-8.3.0 on ppc64le

It fails with the following:

$ diff -u Makefile Makefile.new
--- Makefile    2020-03-20 05:37:40.000000000 +0200
+++ Makefile.new        2020-05-19 10:55:45.000000000 +0200
@@ -1,5 +1,6 @@

 .PHONY: all clean
+ CC = gcc

 all: passh
$ make
        gcc -O  passh.c -o passh
passh.c:359:18: warning: 'struct winsize' declared inside parameter list will not be visible outside of this definition or declaration
     const struct winsize *slave_winsize)
                  ^~~~~~~
passh.c: In function 'pty_fork':
passh.c:410:17: warning: implicit declaration of function 'ioctl' [-Wimplicit-function-declaration]
             if (ioctl(fds, TIOCSWINSZ, slave_winsize) < 0)
                 ^~~~~
In file included from passh.c:46:
passh.c:410:28: error: invalid application of 'sizeof' to incomplete type 'struct winsize'
             if (ioctl(fds, TIOCSWINSZ, slave_winsize) < 0)
                            ^~~~~~~~~~
passh.c: In function 'big_loop':
passh.c:727:28: error: storage size of 'ttysize' isn't known
             struct winsize ttysize;
                            ^~~~~~~
In file included from passh.c:46:
passh.c:739:31: error: invalid application of 'sizeof' to incomplete type 'struct winsize'
             if (ioctl(ourtty, TIOCGWINSZ, &ttysize) == 0) {
                               ^~~~~~~~~~
passh.c:740:34: error: invalid application of 'sizeof' to incomplete type 'struct winsize'
                 ioctl(g.fd_ptym, TIOCSWINSZ, &ttysize);
                                  ^~~~~~~~~~
passh.c: In function 'main':
passh.c:928:20: error: storage size of 'size' isn't known
     struct winsize size;
                    ^~~~
In file included from passh.c:46:
passh.c:941:33: error: invalid application of 'sizeof' to incomplete type 'struct winsize'
         if (ioctl(STDIN_FILENO, TIOCGWINSZ, (char *) &size) < 0)
                                 ^~~~~~~~~~
make: 1254-004 The error code from the last command is 1.


Stop.
$ grep -Hnr winsize /usr/include/
/usr/include/netiso/tp_pcb.h:226:#define        tp_winsize _tp_param.p_winsize
/usr/include/netiso/tp_user.h:75:       short   p_winsize;
/usr/include/sys/ioctl.h:96:struct winsize {
/usr/include/sys/ioctl.h:356:#define    TIOCGWINSZ      _IOR('t', 104, struct winsize)  /* get window size */
/usr/include/sys/ioctl.h:357:#define    TIOCSWINSZ      _IOW('t', 103, struct winsize)  /* set window size */

sshpass-1.06 does compile when I add #undefine malloc to config.h.

As mentioned in README.md, sshpass is broken, and I experience it on AIX. sshpass only works intermittently. I'm hoping to give passh a try, but both sexpect and passh does not compile unfortunately, and is not available on AIX Toolbox for Linux Applications. passh does work and compile perfectly on a x86_64 Linux instance.

Thank you

hide password prompt...

hi,
is it possibile to hide the password prompt just like sshpass does?
this is kind of an issue mostly when redirecting command output...
example:

$ passh -p password user@host pwd > out
$ cat out
user@host's password:
/home/user
$
$ sshpass -p password user@host pwd > out
$ cat out
/home/user

Add support for ERE?

Like grep -E.

Not sure if REG_EXTENDED is always defined on all systems. Can use #ifdef.

big -C option is broken by design

Problem definition: Maybe it waits (N+1)'s password prompt, but if no password prompt (or less than (N+1)), then it cause successful ssh program start and infinite waiting block.

How to reproduce: Just try to start, e.g. when there is already public keys, or other variant when no password prompt.

wont compile in freebsd

Hi, I had problems with sshpass in freebsd, so I thought i'd give passh a try.

I need to rsync data from a nas to a freebsd machine. Use of ssh keys is disabled, as a lot of other stuff as well. (Avoid Seagate if you're buying a nas.)

However, I get an error when trying to compile.

$ make
cc -O2 -pipe  passh.c  -o passh
passh.c:805:49: warning: implicit conversion from 'int' to 'char' changes value from 255 to -1 [-Wconstant-conversion]
                            cache[ncache + i] = 255;
                                              ~ ^~~
passh.c:963:20: error: use of undeclared identifier 'SIGWINCH'
        sig_handle(SIGWINCH, sig_winch);
                   ^
1 warning and 1 error generated.
*** Error code 1

Usage Example on Travis-CI

Hi @clarkwang! โ˜€๏ธ
I am attempting to use passh to input the password for an RSA key on Travis-CI.
The passh.c compiles successfully, but when I try to use passh in an ssh command,
it still asks me for the password! ๐Ÿ˜ž
please see: https://travis-ci.org/nelsonic/hello-world-node-http-server/builds/384184242#L458
image

The password for the SSH key is loaded as an environment variable SSH_ASKPASS
but for some reason it is not being "piped" into the ssh command.

What am I doing wrong?

Any help much appreciated. (thanks!)

Do not feed stdin until interactive

Hey!

When connecting with ssh and a key, you can start typing stuff while authenticating and this will be provided to the next process listening to stdin. When using passh, what is received on stdin seems to be transmitted to the remote end even when not interactive yet. Would it be possible to avoid this?

Thank your very much for this program!

Just saying thanks!

I also would like to share that I can use this for more than just inputting the password. For exemple, for unison, I could use this to both enter the password and answer yes to the question Proceed with propagating updates with the unison bidirecional sync tool:

  1. passh -P 'Proceed with propagating updates' -p y passh -P '[Pp]assword: \{0,1\}$' -p password unison ...

unison has the builtin option called -batch to answer yest to this question Proceed with propagating updates, but I had to manually answer yes because the -batch option also implies to ignore conflict and fail silently. But I would not like for it to fail silently, but ask for my input. Then, putting passh to answer y to the input question Proceed with propagating updates fixed my problem because when there is a conflict, y is not a valid answer (but f, <, etc).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.