How to install sshpass on Windows through Cygwin? - windows

In the packages window of CygWin, when I type sshpass, nothing comes up. I tried installing similar packages like openssh etc hoping one of them contains sshpass but no luck.

sshpass is not available as Cygwin package. This means that you need to build and install from source. To build sshpass on Windows (Cygwin):
$ curl -LO http://downloads.sourceforge.net/sshpass/sshpass-1.06.tar.gz
$ md5sum sshpass-1.06.tar.gz
f59695e3b9761fb51be7d795819421f9
Build and install to /usr/local/bin:
$ tar xvf sshpass-1.06.tar.gz
$ cd sshpass-1.06
$ ./configure
$ make
$ sudo make install
Which installs two files
the executable /usr/local/bin/sshpass
man page /usr/local/share/man/man1/sshpass.1
Your Cygwin install needs to have the required tools: curl to download, tar to extract, and autoconf, make and gcc to build. I'll assume reader familiarity with installing packages on Cygwin.

sshpass is not available as cygwin package. This means that you need to build and install from source.
See for reference on existing alternative
https://www.cygwin.com/ml/cygwin/2015-02/msg00042.html

This does not directly answer the question "How to install sshpass on Windows?", but can be much easier solution if you need to automatically enter the password when ssh-ing to a machine on Windows system, you can use Plink (part of PuTTY).
plink your_username#yourhost -pw your_password

Window 10 comes with Linux subsystem, you can install a favor of Linux through Windows Store. Then all Linux commands comes easily. sshpass can be easily installed in the subsystem. WSL(Windwos Subsystem for Linux) is the future.

Related

How to process json in bash script in windows environment

I am writing bash script that is supposed to work both on linux and windows environment. To enable bash on windows we have installed cygwin.
Seems jq lib can handle json but not sure will it work on windows environment too?
Same with sed not sure how to enable it in windows environment?
Some other libraries?
I have jq installed on cygwin and it can handle json data in Windows.
You can install jq on Cygwin by two ways
1) Run this in cmd. setup-x86_64.exe is your cygwin installation binary
setup-x86_64.exe -q -P jq
2) Install apt-cyg(the package manager of cygwin similar to yum) and run on cygwin
apt-cyg install jq
NOTE: The details of installing packages on Cygwin is mentioned How do I install cygwin components from the command line?

How to install sshpass on Mac?

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.
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
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
Another option in 2020 is this homebrew tap, maintained by esolitos
brew install esolitos/ipa/sshpass
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
Solution provided by lukesUbuntu from github works for me:
Just use brew
$ brew install http://git.io/sshpass.rb
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
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
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
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.
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
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
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...

Can openssh be installed on MSYS?

I'm using MSYS in windows 7 and now i need it to provide ssh server service. can openssh be installed in msys like it is in cygwin?
i can find ssh in /msys/bin, and it can be used as ssh client. but no server seems to be installed. how can i install one? i googled a lot but almost every theads leads to openssh in cygwin, that does not apply to my situation.
i compared cygwin and msys and decide to use msys. We need to run some applications both built and supposed to be ran in windows.
what i've tried:
mingw-get install mysys-openssh
test#WIN-L3L622JBT6G ~
$ mingw-get install msys-openssh
install: openssh-5.4p1-1-msys-1.0.13-bin.tar.lzm
installing openssh-5.4p1-1-msys-1.0.13-bin.tar.
install: openssh-5.4p1-1-msys-1.0.13-doc.tar.lzm
installing openssh-5.4p1-1-msys-1.0.13-doc.tar.
install: openssh-5.4p1-1-msys-1.0.13-lic.tar.lzm
installing openssh-5.4p1-1-msys-1.0.13-lic.tar.
test#WIN-L3L622JBT6G ~
$ openssh
sh: openssh: command not found
the package seems to be installed but i don't know how to find the service. do i need to link it or modify the profile?
The answer would be "NO".
Msys provide ssh client but not ssh server, as it's document indicates.
And Openssh cannot be installed on windows without cygwin. you can install a full cygwin and install openssh in cygwin. It's also feasible to only install partial cygwin.
Msys is outdated. Use Msys2, which does support sshd: https://www.booleanworld.com/get-unix-linux-environment-windows-msys2/

sudo command not found on Cygwin

I am currently trying to install and update a few packages on a Windows OS. The only matter is that I am using Cygwin in order to type the commands through a terminal (as I'm aware, I can type in Linux type commands such as cd, ls etc. on Cygwin - I may be wrong). However, when I try to install a package like:
sudo apt-get install paparazzi-dev
I get the reply:
-sh: sudo: command not found.
Does anyone have an idea as to how I can fix this problem?
Run cygwin as administrator.. then you wouldn't need any sudo command.
Cygwin is not a full Linux distribution. Therefore you don't have sudo or the Debian/Ubuntu package manager apt-get. There is a number of packages available from the Cygwin repository: http://cygwin.com/packages/
You have to chose these packages during setup.
Windows does not have sudo, apt, or almost any Linux commands to be exact. Cygwin may allow some, but as programs are not installed on Windows as packages apt-get will not work. Windows programs have installers as .exe or .msi instead.
The Windows version of sudo is called runas in case you need to run something as another user. Or, you can run Cygwin as administrator.
If you have to use the packages you need Linux. You can install it directly to replace Windows, dual-boot or use a virtualization software like VMware VirtualBox.
Making out an explanatory answer from answer here by #Aimal as it worked for me.
Cygwin may not get permissions to create folders and files when run by clicking Cygwin icon that's in normal mode.
Cygwin gets the right authorization only when right click -> "run as adminitrator" on cygwin icon because of that it gets permissions to create folders and files.
Cygwin lets you run certain commands, such as cd, ls, or mv; but it doesn't let you run other commands, such as sudo or apt-get.
If you're trying to add a package to your Cygwin installation, rerun Cygwin Setup. It may still be in your "Downloads" folder. Go through all the steps again. The Cygwin installer will automatically download and install the package you want, and add it to your Cygwin installation. (I think it will probably also upgrade all your other installed Cygwin packages to the latest available versions.)
If your desired package isn't on the Cygwin package list but is on the Cygwin Ports package list, follow the Cygwin Ports installation instructions. Note that Cygwin Ports is separate from Cygwin. Please do not send messages about Cygwin Ports packages to the cygwin.com mailing lists.
If you have years of Linux experience, you may be able to compile the software you want inside Cygwin. This can be challenging.
Perhaps an option simpler than "compile it yourself" is this: You can install VirtualBox, then install your favorite Linux distribution inside the virtual machine, then install your desired package inside Linux. (I like Ubuntu Linux, which has more than 27,000 packages in its "Universe" repository.) Now you can run Linux and Windows at the same time.
I think I tried steps below after doing some research & succeeded (on windows)
1.Install scoop using powershell 3 (iex (new-object net.webclient).downloadstring('https://get.scoop.sh'))
2. do scoop install --global sudo
3. make sure paths (C:\Users\\scoop\shims & C:\ProgramData\scoop\shims) added in environmental path variable.
In my case, I wanted to install curl, but could not create directory /usr/local/curl/lib when running command "make install", because of permission deny. so i need to change /usr/local permission. when i run sudo chmod 755 /usr/local, sudo command not found.
after searching a few solution, found that sudo is not installed by default in Cygwin. But I tried the solution that Aimal gave which is to run Cygwin as administrator. I finally can change the folder permission. Thanks Aimal.

SFTP command in Bash script with Mac OS X

I need to transfer a text file to a remote PC (freeSSH) using SFTP and SSH from a Mac host. These two are connected in a local network.
So is there a way to run an SFTP command (with the username and password provided) from inside the Bash script?
I already tried some scripting with expect, but I didn't get any results.
I found a similar post, How to run the sftp command with a password from a Bash script, but it is for Linux. I have a Mac.
You can download and install sshpass on Mac as well. Get the latest version source from this download link
Rest of the steps on using sshpass are there in the linked answer of mine.
lftp is great for scripting ftp (and sftp, ftps). And you can install it with brew:
brew install lftp
And for installing the latest version of sshpass using homebrew:
brew install https://raw.githubusercontent.com/EasyG0ing1/sshpassBrew/main/Formula/sshpass.rb
You might have to do this to install it:
wget https://raw.githubusercontent.com/EasyG0ing1/sshpassBrew/main/Formula/sshpass.rb
brew install sshpass.rb
Although #anubhava's answer is correct, it points to the sources only and compiling it without help is hard.
To install sshpass on MacOS using brew easily please use this unofficial package:
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
Source: https://gist.github.com/arunoda/7790979

Resources