Set default permissions on created files SSH putty vi touch

Get answers here.

Moderators: BBear, theunknownhost, flaguy

Post Reply
User avatar
Sapphyre
Official Test Penquin
Posts: 3337
Joined: Tue Nov 19, 2002 2:50 am
Location: Canada

Set default permissions on created files SSH putty vi touch

Post by Sapphyre » Sun Mar 06, 2016 2:03 pm

What controls the permissions that are given when creating files and folders using Putty and
vi
touch
mkdir

In file manager, adding a folder gives it 755 and a file 644.
I would like to default to these same perms when I am working as root, and not have to go the extra step with chmod to correct them all the time!

Is it something you tweak in your bash profile or in putty settings or in vi editor ?

Bonus points: Further, can you set a specific file type to use a different permission ?
i.e. Use 755 when you create a file using vi which ends in .pl or .cgi
It's a crested auklet

User avatar
Arf
Official Test Penquin
Posts: 9103
Joined: Tue Apr 09, 2002 12:00 am
Location: IDAHO, USA
Contact:

Re: Set default permissions on created files SSH putty vi touch

Post by Arf » Mon Mar 07, 2016 8:33 pm

I believe "umask" handles the default perms for files/folders.

When migrating I often find the perms messed up. Here's a quick fix on a cpanel server.

Code: Select all

[root /cmd]# cat fixperms 
#!/bin/bash

# Version 2.0 - better handling of add-on domains, plus a little feedback on the process. 
USER="$1"
if [ "$USER" = "" ]; then echo "USER is BLANK"; exit; fi
if [ ! -d /home/$USER ]; then echo "/home/$USER is not a valid directory"; exit; fi

echo "Fixing permissions and file ownership on $USER"
find /home/$USER/public_html -type f -print0 | xargs -I {} -0 chmod 0644 {}
find /home/$USER/public_html -type d -print0 | xargs -I {} -0 chmod 0755 {}
find /home/$USER/public_html -user nobody -type f -print0 | xargs -I {} -0 chown $USER. {}
find /home/$USER/public_html -user nobody -type d -print0 | xargs -I {} -0 chown $USER. {}

# Just in case there are add-on domains:
if [ -d /home/$USER/domains/ ]; then 
  echo "Found some Add-on accounts in /home/$USER/domains, fixing them too"
  find /home/$USER/domains/*/public_html -type f -print0 | xargs -I {} -0 chmod 0644 {}
  find /home/$USER/domains/*/public_html -type d -print0 | xargs -I {} -0 chmod 0755 {}
  find /home/$USER/domains/*/public_html -user nobody -type f -print0 | xargs -I {} -0 chown $USER. {}
  find /home/$USER/domains/*/public_html -user nobody -type d -print0 | xargs -I {} -0 chown $USER. {}
fi
echo "Done."
This is my go-to script when errors come up in a migration.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest