automating a set of terminal ssh commands to a clickable icon?

Discussion in 'macOS' started by Juz, Jun 2, 2012.

  1. Juz macrumors newbie

    Dec 22, 2006
    hi everyone,

    i have set up an old mac mini as a headless server with my usb external harddrive connected to it, and with file sharing and ssh enabled.

    on the same network from my macbook, i wish to be able to eject the external harddrive so that i can take the harddrive with me but leave the mac mini running.

    i consider myself competent with computers, but not to the level of coding and scripting. the macbook is running 10.7.4 and the mac mini 10.4.11

    with the help of google, thus far, i have been able to figure out what to type into terminal on the macbook in order to achieve the desired result of ejecting the harddrive from the mac mini....

    ssh Admin@

    (wait for the password prompt and then enter the password (Admin, same as username).

    diskutil unmountDisk /dev/disk1

    This works, however it's a laborious process to go through for something I will want to do fairly regularly and quickly.

    Is there an easy way to consolodate this process into an icon i can just run from my dock, which will automatically run this code and enter the password? i have looked into writing the code into a "shell script" but could not figure out how to get it to enter the password or how to make it executable.

    i would appreciate any advice! thankyou
  2. Mac-Michael macrumors regular

    Jan 13, 2010
    Best way to do this is with public keys. Here's how

    First you have to generate them. Open Terminal on the client(macbook) and type in
    ssh-keygen -t rsa
    This will prompt you for a location to save the keys, and a passphrase
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/username/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/username/.ssh/id_rsa.
    Your public key has been saved in /home/username/.ssh/
    Press enter/return on every line (this uses the default location and no passphrase/password)

    Now to copy them to the server(mac mini)
    Type these in one at a time because at least for the first two it would ask for the password
    ssh Admin@ 'mkdir -p ~/.ssh ; chmod 700 ~/.ssh'
    cat ~/.ssh/ | ssh Admin@ 'cat >> ~/.ssh/authorized_keys'
    cat ~/.ssh/ | ssh Admin@ 'cat >> ~/.ssh/authorized_keys2'
    ssh Admin@ 'chmod 600 ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys2'
    To check if done properly
    ssh Admin@ 'whoami'
    Now it shouldn't ask for password and would return the username of the mac mini user.

    Last thing is launch AppleScirpt Editor, type in
    do shell script "ssh Admin@ 'diskutil unmountDisk /dev/disk1'"
    File -> Save As..
    File Format: Application

    Give it a name, save to Desktop
  3. Juz thread starter macrumors newbie

    Dec 22, 2006
    incredible, that works absolutely flawlessly. :)

    thankyou SO much for doing that, i would never have been able to figure all that out myself!

Share This Page