1

Hi I have been given a task of copying files from a given server to local machine. Even I can do it manually using the command line but I need to write a script to automate it. I dont have any clue how to do it using shell, how to give the password which we would have done manually. I went through other posts but did not get the precise answer.

Are there better ways than using SCP command?

Thanks in advance

1
  • 6
    If you're using scp, don't use passwords; use a public/private keypair. Commented Nov 26, 2012 at 19:06

1 Answer 1

1

The preferred + more secure way to do this is to set up ssh key pairs

That being said, if there's a specific need to supply passwords as part of your shell script, you can use pscp, which is part of putty-tools:

If you are on ubuntu, you can install it by:

sudo apt-get install putty-tools

(Or use equivalent package managers depending on your system)

Here's an example script of how to use pscp:

#!/bin/bash

password=hello_world
login=root
IP=127.0.0.1
src_dir=/var/log
src_file_name=abc.txt
dest_folder=/home/username/temp/

pscp -scp -pw $password $login@$IP:$src_dir/$src_file_name $dest_folder

This copies /var/log/abc.txt from the specified remote server to your local /home/username/temp/

Sign up to request clarification or add additional context in comments.

1 Comment

The problem with having the password as text in the command invokation is that a simple ps would give the password to anybody who has access to the machine. Perhaps the OP is okay with that, but they should at least be aware.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.