AIX- .netrc NOT working in Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AIX- .netrc NOT working in Linux
# 1  
Old 11-24-2016
AIX- .netrc NOT working in Linux

Hi,
I got an issue in .netrc , please find below SFTP script and .netrc file .
getting error as below, please assist me to rectify, thanks.

Code:
sftp> $ imuploaddata test1.DAT /home/test/
Invalid command.

FTP scripts

Code:
abc@systalk:~/test> cat imftp.sh
#!/bin/sh
filetoftp="$1"
filepath="$2"
echo "\$ imuploaddata $filetoftp $fi


.netrc macro

Code:
abc@systalk:~/test> cat ../.netrc

# machine MVS2.MAS.NET login TS19610 password ihsan31
machine s_kulsznas1.kulsz.usr.mas.net login kulsz/\graflite password grafl1te
machine 10.251.21.157 login sysftp password imsw19tp
macdef imupload1
        cd /PROJECT_D/01_source_layer/01_raw_source_files/CPD
        lcd $2
        prompt off
        ascii
        verbose on
        put $1
        quit

macdef imuploaddata
        cd /PROJECT_B/01_source_layer/01_raw_source_files/CPD
        lcd $2
        prompt off
        ascii
        verbose on
        put $1
        quit

# 2  
Old 11-24-2016
The .netrc file is generally used for FTP connection credentials etc., however you seem to want to use sftp which is another thing altogether.

SFTP uses files in (typically) ~/.ssh to store all sorts of things but it's quite different to plain FTP so you can't just copy things around.

More usually you would create a batch file of commands you want SFTP to perform and call them with a -b flag. You would need to either answer login prompts or create an SSH key pair, putting the public key on the target server.


How much do you know about SFTP use, authentication, etc.?



Robin
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 11-24-2016
Hi rbatte1,
Thank you very much for the clarification that .netrc doesnt support netrc.

my understanding is on SFTP is only that he its a secure FTP and and works on port 22 instead of 21.

here can you please explain how best i can convert below codes in order to work with SFTP.

Thank you.
# 4  
Old 11-24-2016
Whilst the general commands within sftp are very similar (get, put, rename, chmod etc.) the mechanism is very different. The connection is designed to be secure, so you cannot force a user & password into it like this:-
Code:
sftp <<-EOSFTP
$userid $password
get file
quit
EOSFTP

....or other forms of pushing input into tools. SSH & similar tools have been designed with their own way of working, the exchange of encryption keys. More goes on than you need to know but the important bits for most of us are that the credentials are generated by the client side in the form of two keys. The private one remains on the client side and is used for decrypting the incoming data, and the public key can be shared around.

If a server has a public key (or multiple public keys) stored in the correct place in a secure manner, the owner of the private key is able to connect with a passphrase. Often, for automated tasks, this passphrase is null so the login becomes automatic.

The process to follow to set this up would be:-
  • Generate a pair of keys, usually using ssh-keygen
  • Copy the public key (written to ~/.ssh/rsa_id.pub or ~/.ssh/dsa_id.pub by default) to the server you wish to connect to.
  • Append to (or create) the file ~/.ssh/authorized_keys with the contents of the public key
  • Check that the permissions for ~/.ssh are 700, owner for the correct user.
  • Check that the permissions for ~/.ssh/* are 600, owner for the correct user.
  • You should then be able to open an ssh connection which will ask you to store the fingerprint details which means you are accepting the public key of the server you are connecting to.

The public keys are used to encrypt the data and the private keys are used to decrypt it, but this then becomes automatic from your point of view.

After you can open an ssh connection, you should be able to use sftp in your script. Depending on how complex your needs, you might be able to use a here document like this:-
Code:
sftp $user@$server <<END
get remote-file local-file
END

....or you could create a batch file like this:-
Code:
$ cat simple.batch
get remote-file local-file
$ sftp -b simple.batch  $user@$server

Have a go, and let us know if you get stuck. I have probably missed something or not explained it clearly so it probably won't work first time. I must say that I have never used macdef so I'm not sure how this could be written, but there are bound to be options.


I hope that this helps,
Robin
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 11-24-2016
Quote:
Originally Posted by Riverstone
my understanding is on SFTP is only that he its a secure FTP and and works on port 22 instead of 21.
It's an entirely different protocol, ssh, emulating FTP for convenience's sake.

What it does not -- will not -- cannot do, is use stored passwords. It intentionally does not support .netrc, or passwords over pipe, or passwords over commandlne, or passwords over environment, or any other insecure way of storing passwords. This is a security feature. This breaks a lot of designs of old - a lot of bad, insecure designs of old.

You have to generate a set of key files in advance, and share them with the server, before you can noninteractively login instead.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Simple sed command not working; could be a Mac/Linux vs. PC/Linux issue

Hello, I am on a Mac and trying to clean up some monthly files with a very simple SED: sed '3,10d;/<ACROSS>/,$d' input.txt > output.txt (from the input, delete lines 3 - 10; then delete from the line containing <ACROSS> to the end of the file) then output to output.txt Even when I try... (2 Replies)
Discussion started by: verbatim
2 Replies

2. UNIX for Beginners Questions & Answers

AIX 4.3 - Need help - Printers not working

I am running an old IBM P-Series server running AIX 4.3 (I know a dinosaur). The OS has not been updated. We had a hard drive failure last weekend, and I was able to get most of the system back up, however, I have 3 line printers and 3 label printers that I can not get working. I have tried... (2 Replies)
Discussion started by: Patrick.Crocker
2 Replies

3. Linux

FTP not working under Linux but working under any other OS ??? Very strange

Dear all, I am totally despaired and puzzled. Using Filezilla under Windows under the same network as our Linux servers is working. Using FTP command-line client under any of our Linux debian servers is not working ! I tried with different FTP servers -> same problem ! All commands are... (12 Replies)
Discussion started by: magix_ch
12 Replies

4. Red Hat

Netrc for Linux

What is the proper format for configuring the netrc file for linux. On Solaris it was: Machine <machinename> login Domain\\login password passwordname (1 Reply)
Discussion started by: soupbone38
1 Replies

5. UNIX for Advanced & Expert Users

rm -rf not working on AIX 6.1

Hi Guys, I have never seen this happen before, but created a directory as a user when installing some software, software install fails so I try and remove the directory as root and get an error. There is no processes using the folder see output: ls -l total 446336 -rwxr----- 1 u0008862... (2 Replies)
Discussion started by: chris5126
2 Replies

6. AIX

suid not working on AIX ?

Hello, I'm running AIX 6.1 box. I tried to use suid on binary file but it doesn't work. (I set suid on /usr/bin/sleep and tried to run it as user1(sleep owner is bin) - and program still runs as user1. It shoud run as bin isn't it ? - This test run as expected on Linux box) Filesystem is... (3 Replies)
Discussion started by: vilius
3 Replies

7. Shell Programming and Scripting

*/5 not working in AIX

Hi Guys, I tried to schedule a script for every 5 mins. i tried */5 but it is not working. Is writing every 5 mins is the only way to do it? like below 05,10,15,20,25,30,35,40,45,50,55 05-08 Thanks And Regards, Magesh (11 Replies)
Discussion started by: mac4rfree
11 Replies

8. AIX

Can I make application for AIX while working on Linux Box

Hi all, I had a large application created using Visual C++. I ported that application using WINE to the Linux platform (ofcourse x86). Now I have to port the same application to AIX which runs over IBM mainframe. I dont have mainframe available but it is required for me to port my application to... (1 Reply)
Discussion started by: noble_curious
1 Replies

9. AIX

^P Not working on AIX.

I'm working on an AIX box, and I generall prefer emacs command line editing in ksh. Most control-commands are working, except not control-P (Recall previous command). ksh set - o emacs ^p Does not result in the expected outcome. does anyone know why this might be? (0 Replies)
Discussion started by: akbar
0 Replies

10. UNIX for Advanced & Expert Users

.netrc limits in Aix 4.3

Does anyone know what the max char limit is for login in .netrc? Thanks, Jeff (0 Replies)
Discussion started by: lawadm1
0 Replies
Login or Register to Ask a Question