Reputation: 1058
I know this question has already been asked several times but I got another problem. I have a part in my script where I connect through ssh
and scp
and everytime I run the script it always ask for the password. Most of you would probably answer that I should use expect
or sshpass
yet I don't have any of this two. I tried running:
compgen -c
and there's no expect
and sshpass
existing.
Are there any alternative commands? I would really appreciate your help. Thanks
Update: I also can't install any of this since I'm only an ordinary user.
Upvotes: 2
Views: 625
Reputation: 25579
If you don't want to set up keys for passwordless access (against the rules?), you can set up "SSH connection sharing".
Insert these lines into your .ssh/config
file:
ControlMaster auto
ControlPath /tmp/ssh_%r@%n:%p
ControlPersist 8h
Now, when you log into a server from the machine with that config it will ask you your password the first time, and won't ask again until 8 hours of idle time have passed (so, you'll get asked once per day, usually).
What it's doing is keeping the connection open in the background, and then reusing the same connection for all your SSH sessions. This gives a useful connect-speed boost, and means you don't need to re-authenticate. All-in-all, it's great for accelerating scripted SSH and SCP commands.
Upvotes: 2
Reputation: 1058
First I logged in to server A as testuser and entered the ff command:
ssh-keygen -d
Do not enter any passphrase.
This will generate files in the folder ~/.ssh/
Then scp
the file rsa_id.pub
(public key) to server B.
scp ~/.ssh/id_dsa.pub testuser@B:/home/testuser/.ssh/authorized_keys2
Do the same vice versa (if you want access to both). Then you can now transfer from one server to the other without the being asked for your password.
Upvotes: 2