It’s a fairly simple procedure to have auto SSH enabled to any of SSH supported system. It all needs the system to have Public & Private RSA keys generated and configured between the hosting and connecting system.
On the System to which you want to SSH, you need to run through below sequence of commands:
- ssh-keygen -t rsa
- cd .ssh
- cat id_rsa.pub >> authorized_keys
- chmod 600 authorized_keys
On the system from where you want to remotely connect to the above system you need to download and install the Private Key so that whenever you attempt to SSH the private key in your system cache would be used for authentication and you wouldn’t be prompted for password. Below are the sequence of the steps:
- cd .ssh/
- scp email@example.com:/Users/admin001/.ssh/id_rsa .
Below is the scenario where I’ve had this setup to make automated commands to be executed on my MAC system from my Windows System via Shell scripting without needing me to provide the password for every ssh attempt.
Enable SSH on your MAC OS X Systems: Systems Preferences > Sharing > enable “Remote Login” as shown below. Choose All users if you’d like to let any users to do SSH to your MAC.
Install Cygwin on your Windows System from which you want to remotely connect to the MAC system via Command Line without providing Password.
Launch the Cygwin shell by running the script located at: "C:cygwin64Cygwin.bat"
Run below sequence of steps in the MAC System. You can do this by locally logging on to the MAC and launching Terminal. Or from Windows System launch the Cygwin and SSH to the MAC system. Here I am doing it via Cygwin on Windows:
$ ssh firstname.lastname@example.org
Last login: Mon Sep 23 19:27:10 2013 from gunnala-laptop.testlan.lan
macmini:~ admin001$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/admin001/.ssh/id_rsa):
Created directory ‘/Users/admin001/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/admin001/.ssh/id_rsa.
Your public key has been saved in /Users/admin001/.ssh/id_rsa.pub.
The key fingerprint is:
The key’s randomart image is:
+–[ RSA 2048]—-+
| .. oG.o.. |
| o…- . |
| . . . |
| . . |
| . . S |
| . o + df |
| . .. o o |
|+ o99 + |
|.o..++. > |
macmini:~ admin001$ cd .ssh
macmini:.ssh admin001$ ls
macmini:.ssh admin001$ cat id_rsa.pub >> authorized_keys
macmini:.ssh admin001$ chmod 600 authorized_keys
macmini:.ssh admin001$ exit
Connection to 220.127.116.11 closed.
Now on the client systems you need to have the Private key installed from the MAC. For which you’ll need to follow below steps:
$ cd .ssh/
$ scp email@example.com:./ssh/id_rsa .
scp: ./ssh/id_rsa: No such file or directory
$ scp firstname.lastname@example.org:/Users/admin001/.ssh/id_rsa .
id_rsa 100% 1675 1.6KB/s 00:00
$ ssh email@example.com ps -Ajc | grep loginwindow | grep standuser002
$ ssh firstname.lastname@example.org ps -Ajc | grep loginwindow | grep standuser00*
standuser001 37501 36920 37501 0 0 Ss ?? 0:00.54 loginwindow