SFTP syntax without specifying private key location (no password)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers SFTP syntax without specifying private key location (no password)
# 1  
Old 04-30-2013
SFTP syntax without specifying private key location (no password)

Hi all,

I need to connect using SFTP from Red Hat to Windows. Connection between servers work when I specify location of my private key in the script. However, I want to use syntax without private key location specified. I know this should work, as I found it in older scripts.

Scripts were previously executed from Suse and worked, now they should be run from Red Hat. Working SFTP was against prod server, now we first need to get test working.


working syntax is this (executed from one folder above .ssh):
Code:
sftp -oPort=22 -oIdentityFile=.ssh/sftp_user_cert "ntserv02\\\\sftp_user@ntserv02.cz"

the syntax that I wish to use (that is in the scripts already) is this:
Code:
sftp -oPort=22 "ntserv02\\\\sftp_user@ntserv02.cz"

Right now in terminal it queries me for password and scripts gets permission denied.


In script, it looks like this:
Code:
$SFTPCMD -oPort=$PORT "$LOGIN@$SERVER"
with configuration as follows:
LOGIN=ntserv02\\\\sftp_user
SERVER=ntserv02.cz 
SFTPCMD=sftp
PORT=22

.ssh folder is located in:
/appl/home/user/.ssh/sftp_user_cert
privileges are:
-rw-------. 1 user user 668 Apr 22 15:57 sftp_user_cert

scripts will be executed from (using sh):
Code:
/appl/home/user/unload/unl1/run_unl1

On target windows certificate is saved in the correct directory (C\Users\sftp_user\.ssh\authorized_keys\sftp_user_cert.pub)


Please suggest what settings to change so my script would work without certificate specification (and without asking for password).

Thanx for all suggestions.

---------- Post updated at 04:53 PM ---------- Previous update was at 01:57 PM ----------

Solved it ourselves, if anyone else needs to do it, here is the way:
1) check, if you have in ENV text entries for ssh - SSH_AUTH_SOCK, SSH_AGENT_PID

if not go to step 2 Smilie if yes no idea

2)
Code:
#set up sftp without certificate requirement
# see if ssh agent is running
ps -ef |grep ssh-agent
# if running kill process

# create env file
/usr/bin/ssh-agent > .ssh/environment
chmod 700 .ssh/environment
#list contents
cat .ssh/environment
#copy each part of contents (separated by ;) and execute
# eg. for us:
SSH_AUTH_SOCK=/tmp/ssh-blahblahblah/agent.1234; 
export SSH_AUTH_SOCK;
SSH_AGENT_PID=5480; 
export SSH_AGENT_PID;

#add configuration with path to private key
ssh-add /home/user/.ssh/sftp_user_cert

#add identity to agent
/usr/bin/ssh-add -l


#add to end of /appl/home/user/.profile following text:
SSH_ENV="$HOME/.ssh/environment"

function start_agent {
     echo "Initialising new SSH agent..."
     /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
     echo succeeded
     chmod 600 "${SSH_ENV}"
     . "${SSH_ENV}" > /dev/null
     /usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
     . "${SSH_ENV}" > /dev/null
     #ps ${SSH_AGENT_PID} doesn't work under cywgin
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
         start_agent;
     }
else
     start_agent;
fi


Last edited by vbe; 04-30-2013 at 10:53 AM..
This User Gave Thanks to yavvie For This Post:
 
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. OS X (Apple)

Using a private key with SSH in terminal

Before you get the wrong idea, I am not looking for how to generate one. I have a key from a server admin but I can't figure out how to use it in OS X. I have the key, the address and everything I should need but there doesn't seem to be a step by step on how to install the key and use it in... (4 Replies)
Discussion started by: kylebellamy
4 Replies

3. Shell Programming and Scripting

Password in sftp NOT with key

I've been trying to get out of this, but my manager wont budge. He wants to sftp files from a server while passing the password in the script. I have said we need to use keys...he said no. I asked if we had expect capability...no. He said "use -b batch file command" I have checked every... (1 Reply)
Discussion started by: MJCreations
1 Replies

4. Shell Programming and Scripting

Private Key

I have two types of files pubring.pkr secring.skr secring.skr is encrypted and not able to read. How can i read secring.skr in text format after decrypting ? is there any way of decrypting this file? Unix HP - UX Version. (4 Replies)
Discussion started by: airesh
4 Replies

5. Shell Programming and Scripting

Auto Script to Access external Server via SFTP using Password and Key

Hello All, I am stuck! I have access to an external server via SFTP. In order to access the external server I was given a specific port, password, and a ppk. I would to create a script on my server end that can I can setup as a corn job, that will connect to the external server and... (1 Reply)
Discussion started by: kingr008
1 Replies

6. UNIX for Dummies Questions & Answers

Secure private key

Hello all, We have unix environment and we would like to use ssh public and private key to move between server using ssh. I do know how to test this and have it up and running on some sandbox...but my question is how would one secure the PRIVATE KEY....we are not using a passphrase...and i know... (1 Reply)
Discussion started by: abdul.irfan2
1 Replies

7. UNIX for Dummies Questions & Answers

Extracting a Private key from a keystore?

Hi everyone! I know you can extract public keys from a keystore using the keytool command. But what is the process to extract a private key from a jks keystore and import into another jks keystore using keytool? Any guidance would be greatly appreciated! I can't seem to find anything, I do... (0 Replies)
Discussion started by: Keepcase
0 Replies

8. Solaris

Multiple private key to be uploaded

I would like to ask if you have a procedure on how to upload multiple private key for multiple users in solaris? I was only able to add one but when I tried to add several key, it fails. example: a. user1: user1.ppk b. user2: user2.ppk Each with different password on the server. Pls advise (6 Replies)
Discussion started by: lhareigh890
6 Replies

9. 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

10. Shell Programming and Scripting

SFTP in Shell Script with RSA-KEY or password.

I am trying to SFTP to a couple sites. One has an RSA-KEY that was sent to me. Currently I am running that manually using WinSCP. I would like to set it up as a CRON process on our Linux host (Sun). Can I use the rsa-key they sent me in any directory or does it need to be placed in a specific... (2 Replies)
Discussion started by: alemat
2 Replies
Login or Register to Ask a Question