Solved

FTPerror.NETRC

Posted on 2011-03-04
7
775 Views
Last Modified: 2012-05-11
I have a shell script that uses ftp to copy files from machine another machine

/sips @ ftp rs100
connect to rs100.xx.xx
220 rs100 FTP server ready
Error - .netrc file not correct mode
Remove password or correct mode
221 goodbye

Does this mean the .netrc file on server a has incorrect password.

I added a line for correct password for sips and i tried it manually and it works.

any idea.
0
Comment
Question by:sam15
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Assisted Solution

by:clayhopkins
clayhopkins earned 200 total points
ID: 35039259
It probably means you either don't have access to read the source file, or write access on the destination folder.  Start by verifying that the ftp user or the usergroup that the ftp user belongs to has the correct permissions in both places.
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35039365
The .netrc file must only be readable and writable by the owner - not by group or other.

so

   chmod 600 ~/.netrc

and try again
0
 

Author Comment

by:sam15
ID: 35041017
kind of stange.

when i did chmod 600 it seems to run but i ran into other issues.

I had chmod 777 on the .netrc file, can this be an issue?

also i have 3 accounts in the .netrc file. which login does it read?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Assisted Solution

by:clayhopkins
clayhopkins earned 200 total points
ID: 35041923
chmod of 777 means anyone that can access your machine has full permissions (read, write, execute) on that file.  Not a good thing!  It should only be accessible by the file owner, hence the chmod of 600 as shown by simon.

Do you have three accounts listed under one machine name in the .netrc, or three machines each with their own user account?  There should only be one username/password pair per machine listed.
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35044422
Not only can anyone read and write your .netrc file (with 777 permissions), but the ftp program will ignore it.  It will *only* read that file and use the entries in it if the permissions are 600 (or 400 or 700, but 600 will do fine).
0
 

Author Comment

by:sam15
ID: 35046548
.netrc had two machines (one account for each).

then i added a second account (3rd line)  for 1st machine. Does this impact anything? would the program use the first line or 3rd line..

Are you also saying that the ftp program would not run with 777 permissions assigned. kind of strange. let us say i want all users or programs owned by others to run it.
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 300 total points
ID: 35046648
You can only have one account on each machine in .netrc - when you run the ftp program, it uses the supplied machine name to look up the single username and password to use.  If you have two accounts in .netrc for the same machine, the result may not be consistent or reliable.

Since ftp uses the exact hostname to look up the entry, it is possible to have two accounts on one machine if there is an alias available for that machine.  For example, if you are accessing a machine on your network and you can either use the bare hostname (e.g. ftpserv), or the hostname+domain (e.g. ftpserv.homedom.com), then you could have one entry in .netrc using ftpserv, and another for another account using ftpserv.homedom.com.  You then use the correct name for the account you want to access.

The .netrc file is specific to a single user (since it is in that user's home directory), and only that user can be allowed to read/write it.  If the file is readable or writable by anyone else (in the same group or not), then the ftp program will either ignore it (and prompt for username/password) or will, as in your case, stop.  

The permissions for the ftp program itself are separate.  They will probably be 755 or 555, so that anyone can execute the program, but only the owner can write to it (for 755) or nobody can write to for (555).  Having 777 permissions on the ftp program is very dangerous - it means that anyone can overwrite the program with a potentially dangerous new version.

So, on my local machine, I have:

$ ls -lL ~/.netrc /usr/bin/ftp
-rw------- 1 sr    sr     61 2011-02-04 15:23 /home/sr/.netrc
-rwxr-xr-x 1 root root 74123 2010-05-14 03:45 /usr/bin/ftp

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now