Secure copy help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Secure copy help
# 1  
Old 04-08-2011
Secure copy help

I want to use scp in a script and have two questions:

1. Is there a way to use password in script, so script does not halt and ask for my password for remote box half way through?

2. The code below copies the file to my home directory on the remote server. How can I copy "file" to the same location on the remote server as this server? E.g if file path on current server is /etc/p1/p2/p3 it should be at that location on the remote server as well. If that path does not exist on remote server it should create it!

scp file user@server:~/

Thanks
# 2  
Old 04-08-2011
No, you must set up ssh keys to have passwordless scp operation.
ssh-keygen: password-less SSH login
Code:
scp file user@server:/full/path/to/file

~ or ~/ will not be expanded by scp. Those are ksh and bash expansions. scp does NOT create directores. use sftp instead.
# 3  
Old 04-08-2011
OK thanks ill have a look into sftp
# 4  
Old 05-16-2011
Technically, scp does create directories if you specify the -r option but that means you need to copy the entire directory and not just a single file:

-r Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.

Example using scp locally:

/home/blytsplyk: ls -lr dir1
total 4
drwxr-xr-x 2 blytsplyk users 4096 May 16 19:30 tmp
-rw-r--r-- 1 blytsplyk users 0 May 16 19:27 file1
/home/blytsplyk: ls -lr dir2
ls: cannot access dir2: No such file or directory
/home/blytsplyk: scp -r dir1/* dir2
dir2: No such file or directory
/home/blytsplyk: mkdir dir2
/home/blytsplyk: scp -r dir1/* dir2
/home/blytsplyk: ls -lr dir2
total 4
drwxr-xr-x 2 blytsplyk users 4096 May 16 19:31 tmp
-rw-r--r-- 1 blytsplyk users 0 May 16 19:31 file1

As for the original question, while your home directory may not have the same name on the remote system as it does on the local system, by default, if you do not specify a directory name, scp will use the home directory on the remote system when copying the file. Therefore, if you simply want to copy a file from your home directory on one system to your home directory on another system, you can just do this:

scp file user@server:

There is no need to specify the trailing ~/. In fact, if your account name is the same, there is no need to specify user@ either. And, finally, if you set up your ssh keys, there would be no need to enter your password. I don't personally use sftp since I don't have a need to automate transfers between Windows and Unix machines but I believe newer version of sftp take advantage of ssh so you would still need to set up ssh keys if you want to avoid manual password entry.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to copy the directory but not copy certain file

Hi experts cp bin root src /mnt but not copy bin/bigfile any help? ( I post this thread in the "redhat" forum wrongly, I don't know how to withdraw that question in that wrong forum) Thanks (6 Replies)
Discussion started by: yanglei_fage
6 Replies

2. UNIX for Advanced & Expert Users

Secure Copy - File Transfer between 2 server

Using RCP command we can transfer file from one server to another server. While transferring we can rename the file also e.g. File name = FILE123.txt (lying on Source server = oldserver) Target Server Name = newyour Renamed File = FILE456.txt rcp FILE123.txt newyour:./FILE456.txt... (1 Reply)
Discussion started by: Pash
1 Replies

3. UNIX for Advanced & Expert Users

Secure Copy, scp

Is there a way we can avoid asking of password when we transfer file from one Unix server to another server using SCP command. Or Is is possible that the batch file in unix in which I am giving the SCP command takes the password and transfer the files automatically without me typing the... (1 Reply)
Discussion started by: Pash
1 Replies

4. Shell Programming and Scripting

Help with Secure Copy (SCP) command

Hi, I am in the process of converting ftp transfres to SCP in my scripts. Have some doubts with SCP command 1) currently script puts a list of ftp commands in afile and paasses the file to ftp as input echo "user abc pwd" >inputfile echo "ls *" >> inputfile echo "quit" >> inputfile... (5 Replies)
Discussion started by: justchill
5 Replies

5. UNIX for Dummies Questions & Answers

What is in-core copy and disk-copy of i-node table?

I have found a question from the exercises of my study mat. The question is "Why are there a in-core copy and a disk-copy of i-node block and super block?" If any one know the proper answer then please send me..... (1 Reply)
Discussion started by: dearanik
1 Replies

6. Solaris

Secure FTP Problem using Sun SSH on Client system F-Secure on Server system

I am using shell script to do secure ftp. I have done key file setup to do password less authentication. Following are the FTP Details: FTP Client has Sun SSH. FTP Server has F-Secure. I am using SCP Command to do secure copy files. When I am doing this, I am getting the foll error scp:... (2 Replies)
Discussion started by: ftpguy
2 Replies

7. UNIX for Dummies Questions & Answers

SCP - Secure copy with Certificates exchange.

Will an scp command always copy the files in an encrypted mode? After trying this, I have got message Host Key not found in the database. & Unable to write host key in my user directory. Please anyone has an idea, how we can have secure copy with certificates exchanged successfully? (0 Replies)
Discussion started by: videsh77
0 Replies

8. Shell Programming and Scripting

how to use SCP (secure copy) in UNIX

i have to transfer a file from one server to another. say, my script is running on server 'A' and one file has to be transferred from server 'A' to server 'B' using SCP. i am using it as: sourceserverA> scp -P <port> userid@serverBhostname:/put/this/here <sourcefile path> but it is giving... (1 Reply)
Discussion started by: dharmesht
1 Replies

9. UNIX for Dummies Questions & Answers

looking for a secure copy program (scp)

Hi could someone tell me where to find a secure copy prog. for unix and windows thnx a lot helios (4 Replies)
Discussion started by: helios
4 Replies
Login or Register to Ask a Question