how to Pass , Password for ssh in linux without using sshpass or expect package


Can I pass password while performing ssh in linux. If I dont have to use packages like sshpass and expect. Is there any way to use ssh where I can pass the password for remote host.

Shweta AgarwalAutomation EngineerAsked:
Who is Participating?
Rajat SehgalFounder Enhance TechnologyCommented:
Create Public and private key using ssh-keygen
#ssh-keygen -t rsa
It will ask for the location to save the key
Default location : /root/.ssh/id_rsa
Next It will ask passphrase. (u can do it without a password also, for that just enter )
It will create Private key and public key. See the out put
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/
ssh-keygen -t rsa

Upload public key to the server which you want to upload
#ssh-copy-id -i /root/.ssh/ root@
(Here is a example ip address)
It will automatically copy your public key to .ssh/authorized_keys

You can upload the public key to multiple servers using same command ( ssh-copy-id ). Next time onwards the server will not ask the user ID and password
Joy DingenenICT system consultantCommented:

you could just use
on the source:
ssh-copy-id user@target

Open in new window

after that the ssh session will be on key-pair authentication (only with that user ofc).

Hope that helps,
Joy DingenenICT system consultantCommented:
We both said the same
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.