How to use SFTP from command line without entering user and password | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

How to use SFTP from command line without entering user and password

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-28-2008
Hangman2 Hangman2 is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 25 June 2013, 12:06 PM EDT
Posts: 62
Thanks: 3
Thanked 0 Times in 0 Posts
How to use SFTP from command line without entering user and password

I would like to use SFTP from command line without entering userid and password.

Here is what I have gathered and did.

1) Create a public and private key pair for the protocol you want to use.

To create a key pair for use by SSH2, enter:

ssh-keygen -t dsa

I did that and got following message

Enter file in which to save the key (/home/user1/.ssh/id_dsa): /home/user1/.ssh/id_dsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_dsa.
Your public key has been saved in /home/user1/.ssh/id_dsa.pub.
The key fingerprint is:
71:f5:3d:8f:ae:2a:73:9c:79:92:b0:35:ca:9a:2f:ed

I did not enter a passphrase

2) Next step I did was copied this file to a remote machine to which I want to connect like this

scp /home/user1/.ssh/id_dsa user2@machine2:/home/user2/.ssh/authorized_keys

Now I logged out from user1@machine1 and user2@machine2

and then just write following lines in a korn shell script:


sftp machine2
put test_file

but it asks for password for user2 on machine2.

So what else am I missing???

Sponsored Links
    #2  
Old 02-28-2008
Hangman2 Hangman2 is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 25 June 2013, 12:06 PM EDT
Posts: 62
Thanks: 3
Thanked 0 Times in 0 Posts
I copied the id_dsa.pub key to authorized keys and now scp works


but I still get following error for SFTP


machine1[/home/user1] ==>
machine1[/home/user1] ==>sftp ~/SFTP_test_file machine2:/home/user2/ftptest
Connecting to /home/user2/SFTP_test_file...
ssh: /home/user2/SFTP_test_file: no address associated with name
Connection closed
machine1[/home/user1] ==>
machine1[/home/user1] ==>

=======================



However this is the public key which I don't want to use. I want to use the private key so that noone else can log in.

Sponsored Links
    #3  
Old 02-28-2008
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
 
Join Date: Jun 2006
Last Activity: 1 December 2008, 8:39 AM EST
Location: Madrid (Spain)
Posts: 531
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Hangman2 View Post
machine1[/home/user1] ==>sftp ~/SFTP_test_file machine2:/home/user2/ftptest
Connecting to /home/user2/SFTP_test_file...
ssh: /home/user2/SFTP_test_file: no address associated with name
Connection closed
:
It seems that you forgot a "-b" option before "~/SFTP_test_file". That's why sftp is interpreting that as a servername instead of a commands file.
Regards.
    #4  
Old 02-28-2008
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
 
Join Date: Jun 2006
Last Activity: 1 December 2008, 8:39 AM EST
Location: Madrid (Spain)
Posts: 531
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Hangman2 View Post
However this is the public key which I don't want to use. I want to use the private key so that noone else can log in.
Anyway, you look a little bit confused about how public key cryptography
works... Public-key cryptography - Wikipedia, the free encyclopedia

You might also want to use "expect" instead...
Sponsored Links
    #5  
Old 02-28-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
 
Join Date: May 2006
Last Activity: 4 May 2012, 3:37 PM EDT
Location: Tau Ceti V
Posts: 558
Thanks: 0
Thanked 7 Times in 6 Posts
In a nutshell;
ssh-keygen creates 2 keys, one private, one public (.pub)
The public key goes to the server you want to log on to without using a passwd.
The private key is the key that stays in the server you connect from and needs to be matched by the pub key.

Is there a reason why you want to use 2 commands (sftp, put) instead of one (scp)?
Sponsored Links
    #6  
Old 03-03-2008
ramky79 ramky79 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 25 July 2014, 3:08 PM EDT
Posts: 106
Thanks: 2
Thanked 2 Times in 2 Posts
Quote:
Originally Posted by System Shock View Post
In a nutshell;
ssh-keygen creates 2 keys, one private, one public (.pub)
The public key goes to the server you want to log on to without using a passwd.
The private key is the key that stays in the server you connect from and needs to be matched by the pub key.

Is there a reason why you want to use 2 commands (sftp, put) instead of one (scp)?
what if we want to bring multiple files from server 2?? can we still use scp from server 1.
Sponsored Links
    #7  
Old 03-06-2009
binny binny is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 11 May 2009, 1:08 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
sftp

Do following

sftp user2@machine2
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shellscript- entering the password in scp command aish11 Shell Programming and Scripting 4 04-23-2012 08:22 AM
How to execute command in remote server without entering password? bapu1981 Shell Programming and Scripting 2 04-18-2012 06:49 AM
SFTP with Password in Command Line st3636 UNIX for Dummies Questions & Answers 1 08-06-2011 01:47 PM
SFTP using user id and password Monalisa Shell Programming and Scripting 6 04-28-2010 06:31 PM
Specify password in SFTP command shabu Security 3 10-10-2008 07:19 AM



All times are GMT -4. The time now is 04:21 AM.