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

try like this after your pub key is in located `~/.ssh/authorized_keys` on the remoteIP host.

# ssh -i /path/id_rsa user@remoteIP
# ssh -i /path/id_dsa user@remoteIP
1 Like

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.

 
sftp -B /dev/fd/0 user@servername << Load
#sftp commands
#put or get command
bye
Load

make sure there is no space after Load

1 Like
sftp $user@$host >> $SFTP_Log_file << End_FTPSession
lcd ${Local_directory}
cd ${Server_Source_path} 
mget *.txt
quit
End_FTPSession
1 Like

Hi all,

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

When I try to run the below commands,

sftp brkdsb01@10.14.180.76 << Load
cd /home/data/CoCoRemdies/test
get *.txt
bye
Load

I am getting an error as,

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?
:confused::confused:

Thanks in advance.

Regards.
Vidya N

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

I created DSA keys using the user, brkdcm01 on 10.14.142.67 server.
I am running the script from the server 10.14.142.67 with user id, brkdcm01.

Could you please help me on this?

Thanks in advance.

Regards.
Vidya N

the SFTP servers are of two ways
1.General one and 2. Commercial

1.General:
then the command beow should have been used to create the key

ssh-keygen -t dsa
Place the Copy of the public key generated ( like id_dsa.pub) in ur home dir and a copy in the SFTP server (in .ssh2 directory )

2.Commercial:
ssh-keygen -t dsa
ssh-keygen -e -f id_dsa.pub > id_dsa_dev12.pub
Place the Copy of the public key generated ( like id_dsa.pub) in ur home dir and a copy in the SFTP server (in .ssh2 directory )

The .ssh2 should have 700 permission
and pub key files (.pub) with 600 permission

1 Like