Shell script for SFTP using Public and private keys


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for SFTP using Public and private keys
# 1  
Old 01-30-2012
Shell script for SFTP using Public and private keys

Hi all,

I needed a shell script for file transfering using public/private keys for authentication.
Could you please help me out on this?
A procedure to write a shell script is enough.

Thanks in advance.

Regards.
Vidya N
# 2  
Old 01-30-2012
try like this after your pub key is in located `~/.ssh/authorized_keys` on the remoteIP host.
Code:
# ssh -i /path/id_rsa user@remoteIP

Code:
# ssh -i /path/id_dsa user@remoteIP

This User Gave Thanks to ygemici For This Post:
# 3  
Old 01-30-2012
Error

Thanks for your reply.

I am new to the scripting. What will this command do?

I have placed the public key under authorised_keys. I needed to know how to use SFTP command inside the script.
# 4  
Old 01-30-2012
Code:
 
sftp -B /dev/fd/0 user@servername << Load
#sftp commands
#put or get command
bye
Load

make sure there is no space after Load
This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 01-30-2012
Code:
sftp $user@$host >> $SFTP_Log_file << End_FTPSession
lcd ${Local_directory}
cd ${Server_Source_path} 
mget *.txt
quit
End_FTPSession

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 01-30-2012 at 07:50 AM.. Reason: Please use code tags for code and data samples, thank you
This User Gave Thanks to Sindhuap For This Post:
# 6  
Old 02-01-2012
Hi all,

I am able to put public key under authorised_keys of other server.

When I try to run the below commands,
Code:
sftp brkdsb01@10.14.180.76 << Load
cd /home/data/CoCoRemdies/test
get *.txt
bye
Load


I am getting an error as,

Code:
No DSA host key is known for brkdsb01 and you have 
requested strict checking. Host key verification failed.

Could you please help me on this?
SmilieSmilie

Thanks in advance.

Regards.
Vidya N

Last edited by Franklin52; 02-01-2012 at 04:09 AM.. Reason: Please use code tags for code and data samples, thank you
# 7  
Old 02-01-2012
For which user is the DSA key created and from where are u running the script. If the users or OS differs then the prob would come
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Private and public key encryption

Hi, we have private and public key, encrypt file using public and want to decrypt using private key. can you please advise below commands are correct or other remedy if unix have? encrypt -a arcfour -k publickey.asc -i TESTFILE.csv -o TESTFILE00.csv decrypt -a arcfour -k privatekey.asc... (2 Replies)
Discussion started by: rizwan.shaukat
2 Replies

2. Virtualization and Cloud Computing

Private, Public and Hybrid Clouds

Hi all, Private, Public and Hybrid Clouds I'm now testing OpenStack; Home OpenStack Open Source Cloud Computing Software -Infrastructure as a Service (IaaS) -Platform as a Service (PaaS) -Software as a Service (SaaS) It is an Open Source software. I'm interested to know whether... (0 Replies)
Discussion started by: satimis
0 Replies

3. Shell Programming and Scripting

sftp using private and public keys

hi guys , i have few files i have to do sftp, the public and private key work like a magic , no problem at all the syntax is as below sftp -0 identityfile=~/ure/blsl/loc2/.ssh/id_rsa_ssh1 ssh1@remote >log_dir/file.timestamp<<end lcd folder cd folder put * quit end ================ my... (3 Replies)
Discussion started by: rockymayavia
3 Replies

4. Shell Programming and Scripting

SFTP - Private and Public keys

Hi All, I have a query....say on server A, I have generated the Private and Public keys and shared the public key with server B. Now i can surelyconnect(without password) from server A to server B..... but can i similarly connect from server B to server A as well Regards (1 Reply)
Discussion started by: Arpit Narula
1 Replies

5. Shell Programming and Scripting

What are public keys in ssh and how do we create the public keys??

Hi All, I am having knowledge on some basics of ssh and wanted to know what are the public keys and how can we create and implement it in connecting server. Please provide the information for the above, it would be helpful for me. Thanks, Ravindra (1 Reply)
Discussion started by: ravi3cha
1 Replies

6. Shell Programming and Scripting

SFTP in a shell script without public/private key

Hi everybody, I need some help on writing a script that is able to remote copy file to one server. I already created this types of scripts, and works ok as long as this server I want to copy from is access through telnet. Here is how I do it: ftp -n xxx.xxx.xxx.xxx << _EOF_ user user_name... (6 Replies)
Discussion started by: Alexis Duarte
6 Replies

7. HP-UX

Problem - Creating SSH Public/Private keys. Please help.

HI, I'm trying to create SSH public/private keys using following command. hp023:/users/vikram> ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/users/vikram/.ssh/id_rsa): rsa Enter passphrase (empty for no passphrase): Enter same passphrase... (9 Replies)
Discussion started by: vickramshetty
9 Replies

8. IP Networking

Setting up private and public ip on same machine.

Hi, We have a ftp server which is running on public ip and out side of firewall. Users out side of our network and users of our local network both using the same public ip and doing upload and downloading. Last few days we are facing bandwidth problem as internal network users increased. ... (1 Reply)
Discussion started by: abduljabbar_11
1 Replies

9. UNIX for Dummies Questions & Answers

ssh public/private Keys

Hello, I have an issue with an outside party trying to deliver a file to our server via SFTP. I have setup the .ssh directory under the home directory for the user account that is being used and setup the authorized_keys file with correct permissons etc for .ssh directory and file. We... (2 Replies)
Discussion started by: richo king
2 Replies

10. UNIX for Advanced & Expert Users

SSH public and private keys

Firstly, i apologise if i have posted in a wrong section of the forum. Please let me know which is the correct section my post should go to. I have to SCP a file from one server(server A) to another (server B). I read around that a secure way is to use public and private keys. Assuming my... (2 Replies)
Discussion started by: new2ss
2 Replies
Login or Register to Ask a Question