sftp script file movement

Hi,

I am newbie in unix scripting, I have written a bash script of SFTP that transfer some files from one folder to another within a server , I have two folders test and temp in the directory /home/p5060/sxk124 , the temp folder(/home/p5060/sxk124/temp)contain the files which I through my script put it into test folder(/home/p5060/sxk124/test) and the script run perfectly but my bash scripts resides in a seprate scripts folder(/home/p5060/sxk124/scripts) , Now the one thing I notice before running my my bash scripts, I have to set the permission of files inside the temp directory to

$ chmod 777 inputfilename  

But gives the permission to all ones which as per security is not good ...I want to set the permission such that when I log on to my account through putty and when i execute the the bash script only I will be able to transfer the files...what will be perfect chmod permissions..?Please guide

---------- Post updated at 09:31 AM ---------- Previous update was at 02:51 AM ----------

Hi,

sorry but please guide me on this, as i am stuck up on this.. thanks in advance..!!

744 should be good enough... which will give rwx to you and read permission to others and group...

chmod 744 inputfile

--ahamed

Hi ,
Thanx Ahmed . so by setting this permission when I will log to remote server with my credentials I will be able to run the main script and the files will be transferred as per the business logic of the main script,..and rest others can only read..!!

Yes.
If you don't want others to read, then use 700... do a man on chmod, you will get the idea...

HTH
--ahamed

Hi ahamed,
One more thing to clarify the file movement will take place that is source folder is (/home/p5060/sxk124/temp) to destination .(/home/p5060/sxk124/test) ...that is from temp folder to test folder so I have to set the permission of these file to 744 only or additionally of these directories also . i MEANT SUCH AS OF TEMP FOLDER AND TEST FOLDER ALSO...or by setting the permissions of individual files will work..please advise..!thanks in advance..!!

There is no "right permissions". What permissions you need depend entirely on what you want to do.

On a directory, 'x' permission allows people to cd into it, 'r' allows people to ls in it, and 'w' allows people to create or delete files. Read permission is 4, write permission is 2, execute permission is 1. Decide what permissions you want, add them up, and you get a number between 0 and 7 inclusive.

Do it three times. The last number applies to random passers by, the middle one applies to people in the group owning the dir, and the first applies to the actual user who owns the dir. Don't think about who you want to restrict -- think about who you need to allow, and grant nothing else.

Having done that, you have three digits, like 740. That gives full permissions to the owner, read and ls permission to the group, and nothing at all to anyone else.

For a temp folder or test folder, you'd also want to use the sticky bit, chmod u+s , on the directory itself. This changes how directory permissions work so that files can only be deleted by their owners, having simple write-permissions to the directory itself becomes no longer sufficient.