186

I would like to automate ssh login from my Mac.

It does have a simple solution:

sshpass -p my_password ssh m_username@hostname

But my problem is installing sshpass on my Mac.

12
  • 4
    Why bother with sshpass when you can use ssh keypairs? More secure and dosn't expose password in the process table.
    – alvits
    Aug 27, 2015 at 21:02
  • 13
    On OSX run the command ssh-keygen -b 2048. It will generate a keypair and store them in ~/.ssh. as id_rsa (private key) and id_rsa.pub (public key). Copy id_rsa.pub to linux in the directory ~/.ssh/ and name the file authorized_keys. From here on when you connect to linux you will not need a password. The private/public keypair will be used.
    – alvits
    Aug 28, 2015 at 20:17
  • 1
    Just for someone else who might be trying to follow @alvits very helpful advice: 1) generate the id_rsa file on your local machine and 2) scp the id_rsa.pub to the server's corresponding folder as suggested and 3) rename the id_ras.pub file on the server.
    – yuqli
    Feb 16, 2019 at 2:14
  • 21
    The above answers do NOT answer OP's question. Good alternative, but not explaining how to install sshpass on Mac. There are cases where you cannot copy to the remote system (mine is embedded read only filesystem). So, something like sshpass is a better means to get into the remote.
    – ChuckB
    Feb 20, 2019 at 21:11
  • 4
    By making users go install this from "random GH repos" the Homebrew developers are actively pushing users toward greater risk since those third-party repos have no eyes on them. I too am targeting a read-only embedded Linux. Jun 24, 2021 at 14:05

12 Answers 12

236

Update 2022: Unfortunately, Aleks Hudochenkov is no longer updating his repo. There are a bunch of other repos on GitHub that purport to contain a Homebrew recipe for sshpass. It's up to you which of them (if any) to trust.

Some years have passed and there is now a proper Homebrew Tap for sshpass, maintained by Aleks Hudochenkov. To install sshpass from this tap, run:

brew install hudochenkov/sshpass/sshpass

Tap source

10
  • 22
    Is the source code somewhere? Using something like sshpass without knowing the code is critical
    – muuvmuuv
    Sep 17, 2020 at 7:07
  • 11
    @muuvmuuv, yes. If you look at the formula in that tap, you will see that it downloads the source from downloads.sourceforge.net/project/sshpass/sshpass/1.06/… and builds it locally.
    – smammy
    Sep 18, 2020 at 15:44
  • 1
    Error: Your CLT does not support macOS 11. I use 11.2.
    – ikreb
    Feb 8, 2021 at 7:25
  • 3
    @kjdion84 This helps me: sudo rm -rf /Library/Developer/CommandLineTools and sudo xcode-select --install.
    – ikreb
    Feb 9, 2021 at 13:54
  • 2
    This repository has been archived by the owner. It is now read-only. so I can't request bump its version to latest sshpass :(
    – rogerdpack
    Feb 3, 2022 at 20:01
192

There are instructions on how to install sshpass here:

https://gist.github.com/arunoda/7790979

For Mac you will need to install xcode and command line tools then use the unofficial Homewbrew command:

curl -L https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb > sshpass.rb && brew install sshpass.rb && rm sshpass.rb
5
  • 38
    In 2020 I found this as the best answer Aug 31, 2020 at 14:42
  • 9
    Unfortunately, that didn't work for me Error: Calling Non-checksummed download of sshpass formula file from an arbitrary URL is disabled! Use 'brew extract' or 'brew create' and 'brew tap-new' to create a formula file in a tap on GitHub instead.
    – Alex
    Nov 24, 2020 at 13:09
  • 10
    Update for 2021: curl -L https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb > sshpass.rb && brew install sshpass.rb && rm sshpass.rb Apr 27, 2021 at 9:27
  • Brew has taps now, see some of the other answers...
    – rogerdpack
    Feb 3, 2022 at 19:49
  • I did not need Xcode, the Command-Line Tools were enough.
    – nyg
    Feb 25 at 10:39
46

Another option in 2020 is this homebrew tap, maintained by esolitos

brew install esolitos/ipa/sshpass
2
  • 2
    This is the only answer which literally answers the question. There are concerns with that - a tiny repo could go rogue (and not be noticed right away). But it is an answer. User is advised to exhaust every possible use case first, as there could be other simpler answers (like maybe if you're dealing with a Dropbear host that doesn't store authorized_keys under home directories and that's why your staged public key was rejected, etc) Aug 26, 2021 at 21:16
  • 4
    this is work for me on 2022. macbook pro m1
    – shalk
    Mar 10, 2022 at 2:29
31

Following worked for me

curl -O -L  https://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz && tar xvzf sshpass-1.06.tar.gz
cd sshpass-1.06/
./configure
sudo make install
2
19

Solution provided by lukesUbuntu from github works for me:

Just use brew

$ brew install http://git.io/sshpass.rb
4
  • 11
    note: this is out of date and points to an old version of sshpass
    – Devis L.
    Nov 6, 2018 at 1:17
  • 1
    @DevisLucato Yes, for the one LF the latest version of sshpass, xcode with sshpass src will lead the way. sourceforge.net/projects/sshpass Good luck. Nov 6, 2018 at 3:51
  • 4
    This is now out of date - the comment here: stackoverflow.com/a/62623099/1817774 is more current. Thanks @smammy
    – babelmonk
    Aug 10, 2020 at 21:17
  • Error: Non-checksummed download of sshpass formula file from an arbitrary URL is unsupported! brew extract` or brew create and brew tap-new to create a formula file in a tap on GitHub instead.`
    – rogerdpack
    Feb 3, 2022 at 20:02
10

I found that most of the answers listed here are out of date. To install the latest, I ran this and downloaded directly from sourceforge.net, based on other answers here.

curl -L https://sourceforge.net/projects/sshpass/files/latest/download -o sshpass.tar.gz && tar xvzf sshpass.tar.gz
cd sshpass-*
./configure
sudo make install
2
  • configure: error: in /Users/ME/sshpass-1.08: configure: error: C compiler cannot create executables See config.log for more details
    – Khom Nazid
    Mar 15, 2022 at 21:45
  • 1
    This is better than other answers that use a specific and likely outdated version
    – ehecatl
    Jun 21, 2022 at 22:13
9

Please follow the steps below to install sshpass in mac.

curl -O -L https://fossies.org/linux/privat/sshpass-1.06.tar.gz && tar xvzf sshpass-1.06.tar.gz

cd sshpass-1.06

./configure

sudo make install
1
  • Needs to be updated to /linux/privat/sshpass-1.09.tar.gz
    – Ambareesh
    Jul 30, 2022 at 0:04
5

I just followed the instructions from this article and it helped,

curl -O -L http://downloads.sourceforge.net/project/sshpass/sshpass/1.05/sshpass-1.05.tar.gz && tar xvzf sshpass-1.05.tar.gz

//This creates a directory sshpass-1.05

cd sshpass-1.05
./configure
make
sudo make install
1
  • Thanks, the linked article provides more context
    – ehecatl
    Jun 21, 2022 at 22:09
5

Short answer

To avoid having to rely on unknown Github repositories (directly or via Homebrew taps) just use MacPorts :)

Just install MacPorts and then type

sudo port install sshpass  

Details / Long answer

The idea is to install sshpass via MacPorts instead of Homebrew.

You can have both Homebrew and MacPorts on the same machine, but be careful as some packages are available on both sources, and in that case you should be consistent in order to avoid conflicts.

In such cases, normally I give priority to Homebrew, but sshpass won't be provided by them, as they explicitly say.

In fact, if you type:

brew install sshpass

Then the output will also include this sentence:

We won't add sshpass because it makes it too easy for novice SSH users to ruin SSH's security.

Then in this case MacPorts is the only choice (if you really want to use sshpass).

Some links

Link to the MacPorts project
How to install MacPorts
Link to the sshpass Port on MacPorts

2
  • 2
    Thank you! I wasn't even aware macports was still around. :-) This entire page is a shining example to how security can be made WORSE through blind, inflexible opinion and perspective. All these embedded Linux users had to seek lesser-known, fewer-eyeballs repos due to Homebrew's activist stance. Dec 1, 2022 at 20:58
  • 2
    Yes @ScottPrive you are totally right: perhaps they could put plenty of warnings, or make the package more difficult to install (similarly to what Chrome does when you visit websites with invalid SSL certificates, forcing you to type 'thisisunsafe' on the screen), but they should not completely forbid this, because the consequences will be exactly the ones you said. Dec 2, 2022 at 9:43
3

For the simple reason:

Andy-B-MacBook:~ l.admin$ brew install sshpass
Error: No available formula with the name "sshpass"
We won't add sshpass because it makes it too easy for novice SSH users to
ruin SSH's security.

Thus, the answer to do the curl / configure / install worked great for me on Mac.

2

Just a slight update from the previous answer

curl -O -L  https://fossies.org/linux/privat/sshpass-1.09.tar.gz && tar xvzf sshpass-1.09.tar.gz
cd sshpass-1.09/
./configure
sudo make install

This Worked as on OCT 2021

1

Aargh, the problem with the outdated links. Simply go to https://sourceforge.net/projects/sshpass/ Download latest version and then tar xvzf it and finally cd to the dir where it got unpackedand install with: ./configure make sudo make install I suppose this will also work on every OS with supported C sdk installed...

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.