Non-Interactive SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Non-Interactive SFTP
# 1  
Old 03-11-2010
Question Non-Interactive SFTP

Hi,

I need to sftp from one Unix Server (source) to another (destination) (both SunOS) non-interactively.

I did the following :

1) Generated public key in source server in $HOME/.ssh dir without giving any passphrase
2) Added the contents of the public key generated to authorized_keys2 file in destination server's $HOME/.ssh directory
3) Permissions for the .ssh dir's is 0700 and the key files is 0600
4) Created a file named "confg" in source $HOME/.ssh dir which has the below contents.


Host *
BatchMode yes
PasswordAuthentication no

Still its asking me for a password (not passphrase) when I give sftp destinationuserid@destinationservername in client

When I give the password, its getting connected. But I want non-interactive login where the sftp command should not be prompting me for any password ?

Please help me what I need to do here or if I am doing anything wrong here ?

Thanks,
Sabari Nath S

Last edited by Sabari Nath S; 03-11-2010 at 05:46 PM..
# 2  
Old 03-11-2010
The home directory of the remote account has to be 755. For starters. And the key file gets named authorized_keys. If there are more than one key file just use
Code:
cat keyfile1 keyfile2 ... keyfilen > authorized_keys

If that doesn't help post the output of
Code:
ssh -vvv  remotebox

# 3  
Old 03-12-2010
Also the permissions on the .ssh subdirectory should be set to 700 and the permissions of every file in the .ssh subdirectory should be 600.
# 4  
Old 03-12-2010
Hi,

I had already changed the permissions for all files under .ssh to 600 and the .ssh dir to 700

Client:


Code:
$ ls -ld .ssh
drwx------   2 cdbcdi   other        512 Mar 12 00:04 .ssh

$ cd .ssh

$ ls -l
-rw-------   1 cdbcdi   other         47 Mar 11 14:42 config
-rw-------   1 cdbcdi   other        883 Mar 11 12:48 id_rsa
-rw-------   1 cdbcdi   other        332 Mar 11 12:49 id_rsa.pub

$ cat config
Host *
BatchMode yes
PasswordAuthentication no

Server (Host):

Code:
$ ls -ld b2cint (Home Directory)
drwxr-xr-x   3 b2cint   custapp      512 Mar 11 11:05 b2cint

$ cd b2cint/.ssh

$ ls -ld ../.ssh
drwx------   2 b2cint   custapp      512 Mar 11 14:39 ../.ssh

$ ls -l
-rw-------   1 b2cint   custapp      332 Mar 11 14:39 authorized_keys
-rw-------   1 b2cint   custapp      332 Mar 11 14:38 authorized_keys2

But still it asks for a password.

Last edited by pludi; 03-12-2010 at 05:33 AM.. Reason: code tags, please...
# 5  
Old 03-12-2010
The source needs to have the id_rsa.pub key of the user that will be sending the file copied to the destination server user's home/.ssh/authorized_keys or authorized_keys2
# 6  
Old 03-16-2010
It already has. I have already placed the contents of id_rsa.pub to authorized_keys2 file under $HOME/.ssh dir in the host.
# 7  
Old 03-16-2010
authorized_keys2 has been depreciated for 8 years now. Just cat all of them together into authorized_keys.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

SFTP in non-interactive mode without password

Hello all, can we SFTP to the destination server in a non-interactive mode with out estbalishing the public key of origination server in the destination server? meaning i want to harcode the password as part of the below script or as an variable? Please let me know if there is any better way to... (2 Replies)
Discussion started by: Ariean
2 Replies

2. Shell Programming and Scripting

Sftp : not able to print the echo statements after the sftp transfer

I had the below sftp script working perfectly but the problem is I am not able to send the echo statements . #!/bin/sh echo "Starting to sftp..." sftp admin@myip << END_SCRIPT cd /remotepath/ lcd /localpath/ mget myfiles*.csv bye END_SCRIPT echo "Sftp successfully." echo echo... (11 Replies)
Discussion started by: scriptscript
11 Replies

3. Red Hat

Chroot sftp users, remote sftp login shows wrong timestamp on files

Hello, I have a weird issue, I have RHEL 5.7 running with openssh5.2 where sftpgroup OS group is chroot. I see the difference difference in timestamp on files, when I login via ssh and SFTP, I see four hour difference, is something missing in my configuration. #pwd... (8 Replies)
Discussion started by: bobby320
8 Replies

4. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

5. Shell Programming and Scripting

Interactive script – if then

Hi, I am writing an interactive shell script (ksh) but I have no idea how I could make a condition on it : Variables : rep_config="${rep_tools}/_CONFIG" rep_config_old="${rep_config}/_PROTO_OLD" Here is the interactice part : lst_proto=$(cat... (2 Replies)
Discussion started by: Aswex
2 Replies

6. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

7. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

8. Shell Programming and Scripting

SFTP - non-interactive - using passphrase

Hi, I have written a script that does SFTP successfully without using the password (Thanks to this site :b: ) and it works fine. The thing is - this script uses the public and private key generation with a "null" passphrase. But I now need to write a script that does SFTP non-interactively... (1 Reply)
Discussion started by: sandy0077
1 Replies

9. Shell Programming and Scripting

SFTP- Non-interactive user authentication

Hi All, sftp -b script.txt <hostname> user-authentication through non-interactive way is desired. But, its failing to do so. Could anyone kindly advise. Thanks for any/all help at the earliest. Regards, Dheeraj. (1 Reply)
Discussion started by: dheeruchakri
1 Replies

10. UNIX for Advanced & Expert Users

interactive startup..

i have used the interactive startup in the past on my system to skip wireless mode when I am somewhere out of range of the internet and and have only the 2hrs battery lifetime and no place to connect my laptop to the mains.. i usually skip isdn and networking. what I would like to know is how... (2 Replies)
Discussion started by: moxxx68
2 Replies
Login or Register to Ask a Question