ioswindowsmacosbatch-fileauto-build

Can I ssh to Mac using Windows Command line without using other tool like putty?


I have a CI system on my Windows to build my server code.

Nowadays, I also want to autobuild my IOS project daily, but it can only build in Mac system.

So I write a shell script that can build my ios project on my Mac, and I want to remotely execute my script from Windows.

How can I write a batch file on Windows to remote access my Mac and execute my script there? So I can make my CI system to execute that batch file everyday automatically.

Or... does anyone got other better ways to do this thing?

Thanks!


Solution

  • Get "plink" from the PuTTY download page. Put the command(s) to kick off your Mac shell script in a file (e.g. "maccommands.txt") on your Windows computer. Then make a batch file that contains:

    plink -l macusername -m maccommands.txt your.mac.ip.address
    

    If you don't want to be prompted for a password every time, you could make a public-private keypair with an empty passphrase using PuTTYgen. Save the private key as "pc_rsa.ppk" (or whatever you want to call it). Copy the public key out of the PuTTYgen window to the clipboard, and paste it in a text editor and save it (e.g. as "pc_rsa_pub.txt").

    Then transfer the file with public key over to the Mac, and add its contents to the end of ~/.ssh/authorized_keys, e.g. with cat pc_rsa_pub.txt >> ~/.ssh/authorized_keys Then add -i pc_rsa.ppk to the plink command above to use your private key.

    (This obviously has security implications, so protect the private key file. You could also use -pw password but that has even greater security implications as the password would be plainly visible within your batch file.)