sshpass-win32

repository·main·Indexed 40 days ago

https://github.com/xhcoding/sshpass-win32

A Windows port of the sshpass utility used to provide passwords to SSH clients non-interactively. It supports password input via files, environment variables (SSHPASS), or command-line arguments, and includes features for customizing password prompt detection and automating host key confirmation.

Tokens
1.1K
Snippets
5
Records
7
Agent score
1%

What's inside sshpass-win32

  1. Install sshpass-win32 via Winget or Scoop

    main

    You can install sshpass-win32 using either the Windows Package Manager (Winget) or Scoop.

    Prerequisites:

    • Windows 10 Insider build 17733 or later.
    # Using Winget
    winget install xhcoding.sshpass-win32
    
    # Using Scoop
    scoop install sshpass
  2. Examples of using sshpass-win32

    main

    Below are common usage patterns for sshpass with ssh and rsync.

    # Run a command via SSH using a password argument
    sshpass -p 12345 ssh xhcoding@192.168.139.128 ls
    
    # Use rsync with a specific SSH executable and password
    sshpass -p 12345 rsync -avz -e 'c:/Users/xhcoding/scoop/apps/cwrsync/current/bin/ssh.exe' README.md xhcoding@192.168.139.128:/home/xhcoding/
  3. Use sshpass-win32 command line options

    main

    The sshpass utility allows you to provide passwords to SSH-based commands non-interactively. The general syntax is:

    sshpass [ options ] command arguments

    Password Options

    If no password option is provided, sshpass will attempt to read the password from stdin.

    • -f=<str>: Take password from a file.
    • -d=<int>: Use a specific file descriptor to get the password.
    • -p=<str>: Provide the password as a command-line argument (Note: this is insecure).
    • -e: Use the environment variable SSHPASS for the password.

    Other Options

    • -P=<str>: Specify the string sshpass should search for to detect a password prompt.
    • -v: Enable verbose mode.
    • -k: Automatically confirm 'Are you sure...' prompts for host keys.
    • -h, --help: Show help message.
    • -V, --version: Print version information.
  4. Reference: sshpass command-line options

    main

    The following options are available for the sshpass CLI:

    FlagLong OptionDescription
    -V--versionPrint version information
    -f(none)Take password to use from file
    -d(none)Use number as file descriptor for getting password
    -p(none)Provide password as argument (security unwise)
    -e(none)Password is passed as env-var SSHPASS
    -P(none)Which string should sshpass search for to detect a password prompt
    -v(none)Be verbose about what you're doing
    -k--auto-confirmAuto confirm 'Are you sure...' prompt for host keys
  5. Automate host key confirmation with --auto-confirm

    main

    When connecting to a new host, SSH often prompts: Are you sure you want to continue connecting (yes/no/[fingerprint])?. You can use the -k or --auto-confirm flag to automatically respond yes to this prompt.

    sshpass -k ssh user@host
  6. Use sshpass CLI with various password sources

    main

    The sshpass command allows you to automate password entry for commands (like ssh) by providing the password through several different methods. By default, if no password option is provided, sshpass will attempt to read the password from stdin.

    # Use a password from a file
    sshpass -f /path/to/password.txt ssh user@host
    
    # Use a password from an environment variable (SSHPASS)
    export SSHPASS='mypassword'
    sshpass -e ssh user@host
    
    # Provide password directly as an argument (not recommended for security)
    sshpass -p 'mypassword' ssh user@host
    
    # Use a file descriptor for the password
    sshpass -d 3 ssh user@host
    
    # Default: read from stdin
    echo 'mypassword' | sshpass ssh user@host
  7. Configure sshpass password prompt detection

    main

    By default, sshpass searches for the string password: to detect when it should inject the password. You can customize this behavior using the -P flag if the target application uses a different prompt.

    # Search for 'Enter Pass:' instead of 'password:'
    sshpass -P 'Enter Pass:' ssh user@host