1

I am executing the following in my script: ssh pi@192.169.1.89

Which asks me for a password pi@192.169.1.89's password:

How do I execute the script to create the ssh connection and then pass the password into it, so I don't have to type it?

1

What your looking for is ssh keys, then you wont have to type a password.

To generate RSA keys, on the command line, enter:

ssh-keygen -o -b 4096 -t rsa

NOTE THIS: If you don't password-protect your private key, anyone with access to your computer conceivably can SSH (without being prompted for a password) to your account on any remote system that has the corresponding public key.

Your private key will be generated using the default filename (for example, id_rsa) or the filename you specified (for example, my_ssh_key), and stored on your computer in a .ssh directory off your home directory (for example, ~/.ssh/id_rsa or ~/.ssh/my_ssh_key).

If your account on the remote system doesn't already contain a ~/.ssh/authorized_keys file, create one; on the command line, enter the following commands:

mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys

To copy your key to the remote server:

ssh-copy-id is a utility available on some operating systems that can copy a SSH public key to a remote server over SSH.

To use ssh-copy-id, pass your username and the IP address of the server you would like to access:

ssh-copy-id USER@IP-ADDRESS

ref:

Use Public Key Authentication with SSH

Set up SSH public-key authentication to connect to a remote system

1

There are several ways to do this, but I recommend using public/private keys rather than passing the password (which is possible). There are many other answers on this - but here is a quick how to:

On the machine you are logging in from:

Create a public/private key combination:

ssh-keygen -t rsa

Copy the public key to the remote machine:

ssh-copy-id pi@192.168.1.89

You will then need to type your password, and the public key will be copied to 192.168.1.89. At this point you will no longer be asked for your password upon logging in from the first machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.