2

I have a simple bash application in Mac OS that establishes a SSH connection.

the code is like this:

$ ssh user1@machine.com -p61023

When I run the script, console always prompts asking for a password. (It is a very rudimentary process)

appelelog@sunlineclass.com's password:

How I can automate this process?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
mryuso92
  • 267
  • 4
  • 21

2 Answers2

2
  1. Create a key pair.
  2. Add the private key to the Keychain: ssh-add -K ~/.ssh/host_id_rsa.

Never type the password again, other than the login password.

If you run the server, then other things I do:

  1. Listen on port 422 instead of 22, to reduce break-in attempts.
  2. Only allow login via public/private key pairs, and not passwords.
  3. Only allow login by a select list of users (never root).

This question is off-topic, however, and you should have asked it here.

Droppy
  • 9,691
  • 1
  • 20
  • 27
  • For (1.) look at `/etc/services` pick your favorite unused port. Picking in the *5000-30000* range will keep most of the script-kiddies away. *dsa* keys are deprecated in openssh 7.2 (security reasons), pick an alternate like *ecdsa*. (3.) you can limit users who are members of specific groups with the `AllowGroups` parameter in `/etc/ssh/sshd_config`. Good answer. **Note:** after changing the port, you can specify `Host Port` pairs in `/etc/ssh/config` or `~/.ssh/config` to eliminate having to give the alternate port number. – David C. Rankin Oct 07 '15 at 05:26
  • Your answer is so great, but I used `sshpass` command. (Comment by @Kalanidhi ) By the way, you have my upvote :) – mryuso92 Oct 07 '15 at 05:34
0

@Kalanidhi gave me a hint:

Here is my new script

  sshpass -p 'yourpassword' ssh user@machine.com -p61023
mryuso92
  • 267
  • 4
  • 21