How to change file ownership in SSH?

Bryan McClure

Well-known member
Registered
Joined
Jul 20, 2016
Messages
271
Points
18
I have a zip file and i uploaded it to my vps server but strange thing is, after unzip it then I get all files and folders with no ownership. I had to run this command

chown -R username.username /path/to/my/folder/

to make ownership for new files and folders just uploaded to my server.
This problem didn't happen when I upload file from FTP client program and not zip them.
My question is, how can I change file ownership in SSH? and make this process automatically.
Thanks in advance.
 

farhan786

New member
Registered
Joined
Nov 23, 2017
Messages
12
Points
0
You want to issue the chown (change owner) command, for example:

chown user /home/user

The command above will change just the folder /home/user. If you wanted to change all of the files and folders within a given directory you would use:

chown -R user /home/user

If you wanted to change the user and group at the same time you would use:

chown user:group /home/user
 

mobin

Well-known member
Registered
Joined
Jun 22, 2017
Messages
234
Points
28
Just to say, please be very careful with chown -R command. If you issue it wrongly on your system, it can damage the whole file system. So unless you know what you are doing, do not use chown -R
 

Bryan McClure

Well-known member
Registered
Joined
Jul 20, 2016
Messages
271
Points
18
Bryan McClure
Can you give an example?
I did this command many times on public_html and folders/files on it without any problems.
I don't see any reasons why it can damage the whole file system
 

mobin

Well-known member
Registered
Joined
Jun 22, 2017
Messages
234
Points
28
mobin
Yes if you run chown -R user.user /home/user/public_html, there is no real damage it can make to the system I agree.

But what about chown -R user.user / home/user/public_html or chown -R user.user /home/user ? This can damange the file systems and cause issues on your server. So it is advisible to use chown -R only when you are confident that the command you entered in CLI is proper and complete. When we train new techs, we refrain them from running any cp, mv, chown and chmod commands without permission just to avoid such kind of damages.
 

Bryan McClure

Well-known member
Registered
Joined
Jul 20, 2016
Messages
271
Points
18
Bryan McClure
I remember I did this chown -R user.user / home/user/public_html and no problem but not yet tried this chown -R user.user /home/user
on my hosting /home/user/public_html is linked to real public_html folder so i didn't have any problem with it, it is same as home/user/domains/mydomain.com/public_html
for /home/user, it could contain imap, maildir and other directories and i agree with you, it can damage system file there.
 

mobin

Well-known member
Registered
Joined
Jun 22, 2017
Messages
234
Points
28
mobin
Ok I did not try the exact command and just wanted to outline the damage of chown -R from root. I am not sure about your setup, but if your files outside public_html has different ownerships or your some of your public_html dirs/files demands write permission from web and web service/php is running not as the user related functionalities can break!
 

caredexy

Member
Registered
Joined
Nov 19, 2017
Messages
19
Points
0
As I remember,you need to right-click on a file and then have a option to change the permissions. In order change the ownership of a file, you will need to utilize sFTP. That's it!
 
Older Threads
Newer Threads
Replies
0
Views
2,827
Replies
16
Views
4,887
Replies
3
Views
3,251
Latest Threads
Replies
1
Views
25
Replies
0
Views
180
Replies
1
Views
39
Replies
2
Views
81
Recommended Threads

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top