0 votes
1 view
in DevOps and Agile by (30k points)

I have some n number of files in a directory on my UNIX system. Is there a way to write a shell script that will transfer all those files via SCP to a specified remote system. I'll specify the password within the script so that I don't have to enter it for each file.

1 Answer

0 votes
by (51.2k points)

Instead of hard-coding a password in shell script, it’s better to use ssh keys which is more secure

For that 

$ scp -i ~/.ssh/id_rsa [email protected]:/path/to/bin/*.derp .

your private key should be at ~/.ssh/id_rsa

To generate a key pair:

$ ssh-keygen -t rsa

This will generate both private and public key in locations 

~/.ssh/id_rsa (private key) and ~/.ssh/id_rsa.pub (public key)

To setup the SSH keys for usage (one time task) : 

Copy the contents of ~/.ssh/id_rsa.pub and paste in a new line of ~devops/.ssh/authorized_keys in myserver.org server. 

If ~devops/.ssh/authorized_keys doesn't exist, create it.

Refer: http://www.linuxproblem.org/art_9.html

If still, this won’t work it means the .ssh dir or the authorized_keys files may not have the right permissions (700). Enable the permissions then you can solve this problem.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...