I just did this, and I don’t want to forget how. This explains how to set up a public authentication key and make it executable
First, create your public key. Open the terminal. Navigate to the directory where you want to keep your key. You will have to run your key from this folder once you’re done. In my case, it’s Users/MyName
Now, enter:
1 |
ssh-keygen -t dsa |
It will ask you where to store the key – hit enter for the current directory. You will be prompted for a passphrase. Hit enter if you don’t want to use one, then hit enter again to confirm.
You should see:
1 2 |
Your identification has been saved in /Users/YourName/.ssh/id_dsa. Your public key has been saved in /Users/YourName/.ssh/id_dsa.pub. |
Then a string of digits that are the digital representation of your public key, and some neat ASCII art that is a visual representation of same.
Next, upload your key to your server with scp:
1 |
scp ~/.ssh/id_dsa.pub username@servername.com:.ssh/authorized_keys2 |
Enter your server password when prompted.
You’re good to go. Now you can connect with ssh like so:
1 |
ssh username@servername.com |
And it won’t bug you for a password. But that’s still kind of a lot of typing. Let’s make this an executable.
Disconnect from the server with:
1 |
logout |
Create a text file using vim:
1 |
vim servername |
Type ” i ” to get into insert mode, then:
1 2 3 4 |
#!/bin/bash ssh username@servername.com Esc (to exit insert mode) :wq (to save the file and quit vim) |
Next, make it executable.
1 |
chmod +x servername |
Done deal. Now you can run this command:
1 |
./servername |
And you will connect to the server without any further fuss.