How to install sshpass on Mac?
Asked Answered
D

12

190

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.

Duclos answered 27/8, 2015 at 17:18 Comment(12)
Why bother with sshpass when you can use ssh keypairs? More secure and dosn't expose password in the process table.Feeley
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.Feeley
Just for someone else who might be trying to follow @Feeley 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.Freeboot
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.Straus
While it's good to comment to inform risks, it is unhelpful to withhold direct answers on assumption the user can simply install SSH keys. Try dealing with embedded OS whose root-directory is read-only. Your choices then are continually typing passwords, playing hunt-the-homebrew-tap game, or writing Expect.Stonework
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.Stonework
This answer is still relevant in 2021 https://mcmap.net/q/134674/-how-to-install-sshpass-on-macFunnelform
It seems with "normal" openssh you can pass in a password these days: superuser.com/a/1703039/39364 so you may not need sshpass :)Vladamir
Instead of using scp, you can copy RSA public key to the server like so: ssh-copy-id remoteuser@remotehostnameRatcliff
I agree with @ScottPrive and in fact my answer uses MacPorts instead of relying on random Github repositories or random non-popular websites that claim to be dedicated to open source software.Manicotti
@Kubuntuer82 - TY. I don't know what's worse here, the lack of understanding what "read only embedded filesystem" means. Or homebrew's devs who do understand it, but actively don't care about the use case.Stonework
Is it safe to use SSHPASS ? it doesn't guarantee that it does not share server user host and password ?Federation
D
196

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
Dial answered 27/8, 2015 at 19:59 Comment(5)
In 2020 I found this as the best answerQuadragesima
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.Eolic
Update for 2021: curl -L https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb > sshpass.rb && brew install sshpass.rb && rm sshpass.rbCabinet
Brew has taps now, see some of the other answers...Vladamir
I did not need Xcode, the Command-Line Tools were enough.Tadich
N
252

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

Neiman answered 28/6, 2020 at 13:22 Comment(10)
Is the source code somewhere? Using something like sshpass without knowing the code is criticalNazarite
@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.Neiman
Error: Your CLT does not support macOS 11. I use 11.2.Alkmaar
Same error as @ikreb, Your CLT does not support macOS 11. On latest version of Big Sur.Stockman
@Stockman This helps me: sudo rm -rf /Library/Developer/CommandLineTools and sudo xcode-select --install.Alkmaar
Works on Catalina with XCode 12.3 on 2021-02-18.Nawab
This repository has been archived by the owner. It is now read-only. so I can't request bump its version to latest sshpass :(Vladamir
@Vladamir Ah, that's unfortunate. There are a bunch of repos on GitHub that purport to contain a Homebrew recipe for sshpass. It's up to you which of them (if any) to trust.Neiman
For what little it's worth, I've forked Aleks' repo above and updated to the latest version of sshpass on sourceforge (1.08). brew install stevenhaddox/sshpass/sshpassCletuscleve
looks like sshpass has to support ssh versions to get it working.Enwomb
D
196

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
Dial answered 27/8, 2015 at 19:59 Comment(5)
In 2020 I found this as the best answerQuadragesima
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.Eolic
Update for 2021: curl -L https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb > sshpass.rb && brew install sshpass.rb && rm sshpass.rbCabinet
Brew has taps now, see some of the other answers...Vladamir
I did not need Xcode, the Command-Line Tools were enough.Tadich
S
47

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

brew install esolitos/ipa/sshpass
Soonsooner answered 14/9, 2020 at 14:29 Comment(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)Stonework
this is work for me on 2022. macbook pro m1Dameron
R
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
Rotter answered 11/9, 2020 at 6:18 Comment(2)
Just make sure you already have xcode installed. Please google how to do that, here is one of the link (freecodecamp.org/news/install-xcode-command-line-tools)Monochasium
Add --insecure to curl if you get: SSL certificate problem: certificate has expiredSharl
T
19

Solution provided by lukesUbuntu from github works for me:

Just use brew

$ brew install http://git.io/sshpass.rb
Triplett answered 8/6, 2018 at 3:42 Comment(4)
note: this is out of date and points to an old version of sshpassPumice
@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.Triplett
This is now out of date - the comment here: https://mcmap.net/q/134674/-how-to-install-sshpass-on-mac is more current. Thanks @NeimanWrist
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.`Vladamir
S
12

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
Sleuthhound answered 10/1, 2022 at 23:25 Comment(2)
configure: error: in /Users/ME/sshpass-1.08: configure: error: C compiler cannot create executables See config.log for more detailsInfest
This is better than other answers that use a specific and likely outdated versionCold
S
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
Spanos answered 5/3, 2020 at 9:32 Comment(1)
Needs to be updated to /linux/privat/sshpass-1.09.tar.gzImpeccant
M
6

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

Manicotti answered 28/11, 2022 at 15:11 Comment(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.Stonework
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.Manicotti
B
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
Bovine answered 23/4, 2021 at 11:19 Comment(1)
Thanks, the linked article provides more contextCold
B
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.

Bernal answered 6/4, 2020 at 17:34 Comment(0)
S
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

Spherical answered 6/10, 2021 at 14:28 Comment(0)
M
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...

Mcmillian answered 1/10, 2021 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.