Nathan.Rivard
Posts: 37
Joined: Tue Sep 10, 2019 3:28 pm

Sudo instructions to insert a directory within /home

Fri Dec 13, 2019 4:14 pm

I am attempting to put a custom made directory into the /home directory, but I do not have the permissions to do so. Is there a way to change settings on the Pi to allow me to write whatever I would like without using sudo?

jahboater
Posts: 5057
Joined: Wed Feb 04, 2015 6:38 pm

Re: Sudo instructions to insert a directory within /home

Fri Dec 13, 2019 4:42 pm

Nathan.Rivard wrote:
Fri Dec 13, 2019 4:14 pm
I am attempting to put a custom made directory into the /home directory, but I do not have the permissions to do so. Is there a way to change settings on the Pi to allow me to write whatever I would like without using sudo?
A one-off:

sudo chmod a+w /home

Then you can write to the /home directory (create files and directories) without needing sudo

W. H. Heydt
Posts: 11485
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Sudo instructions to insert a directory within /home

Fri Dec 13, 2019 4:45 pm

That requires root privileges...and it's a feature, not a bug. You can do it either with "sudo mkdir /home/<directoryname>" or "sudo su -" then "mkdir /home/<directoryname>". Or any other method of escalating privileges to root.

The reason for need root privileges is that root owns /home and requiring the privileges that go with the owner of the directory protects *everyone* from having their part of the file structure modified when they don't want that happening. Linux (like unix) is a multiuser system.

jahboater
Posts: 5057
Joined: Wed Feb 04, 2015 6:38 pm

Re: Sudo instructions to insert a directory within /home

Fri Dec 13, 2019 4:47 pm

W. H. Heydt wrote:
Fri Dec 13, 2019 4:45 pm
That requires root privileges...and it's a feature, not a bug. You can do it either with "sudo mkdir /home/<directoryname>" or "sudo su -" then "mkdir /home/<directoryname>". Or any other method of escalating privileges to root.
That still needs sudo.

Giving public write access to /home fixes that.

Not something I would do!

Probably better to move everything down a level in the tree so that its all under one users home area.

User avatar
thagrol
Posts: 2229
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Sudo instructions to insert a directory within /home

Fri Dec 13, 2019 6:37 pm

Nathan.Rivard wrote:
Fri Dec 13, 2019 4:14 pm
I am attempting to put a custom made directory into the /home directory, but I do not have the permissions to do so. Is there a way to change settings on the Pi to allow me to write whatever I would like without using sudo?
Short answer: No.

Long answer:
What are you actually trying to do? /home is the location for users' home directories not for arbitary storage.

You could follow @jahboater suggestion but doing so still requires sudo and would allow any user on the system to create files and folders under /home.

You could do as @W. H. Heydt suggests with

Code: Select all

sudo mkdir /home/some_directory
but that would leave /home/some_directory owned by root with restricted permissions (read and execute only) for normal users. That might work if you don't want normal users to be able to write to said folder and its contents but you'd need to be root to put stuff in there. Or to do any maintenance.

You could do something like this:

Code: Select all

sudo mkdir /home/some_directory
sudo chmod a+rwx /home/some_driectory
That would aloow full read/write/execute permission for that directory without opening up /home. Files and directories created below there would still be subject to the default permissions set by their owning user unless explictly changed.

The best solution? Workout the correct location, owner, and permissions for your arbitary directory in the standard hierarchy and put it there.

The second best solution? Make use of

Code: Select all

sudo adduser
to create a new user with a home directory to put your stuff in. The new user doesn't have to be able to login or have a shell (but having a shell is useful if you need to do maintenance on the files - they won't end up being owned by root if editied etc).

Whichever option you select, read up on linux file and directory permissions; users; and groups before you do anything.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

andrum99
Posts: 1023
Joined: Fri Jul 20, 2012 2:41 pm

Re: Sudo instructions to insert a directory within /home

Fri Dec 13, 2019 8:05 pm

jahboater wrote:
Fri Dec 13, 2019 4:42 pm
Nathan.Rivard wrote:
Fri Dec 13, 2019 4:14 pm
I am attempting to put a custom made directory into the /home directory, but I do not have the permissions to do so. Is there a way to change settings on the Pi to allow me to write whatever I would like without using sudo?
A one-off:

sudo chmod a+w /home

Then you can write to the /home directory (create files and directories) without needing sudo
That's not a good idea - it gives everyone write access to /home. A better idea is to just accept that for certain operations, you need to use sudo.

W. H. Heydt
Posts: 11485
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Sudo instructions to insert a directory within /home

Fri Dec 13, 2019 8:38 pm

thagrol wrote:
Fri Dec 13, 2019 6:37 pm
You could do something like this:

Code: Select all

sudo mkdir /home/some_directory
sudo chmod a+rwx /home/some_driectory
A better choice for that second line would be:

Code: Select all

sudo chown <some_user_account> /home/<some_directory>

W. H. Heydt
Posts: 11485
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Sudo instructions to insert a directory within /home

Fri Dec 13, 2019 8:41 pm

What it all really comes down to is: You can't add a directory under a directory you don't own. Using root privileges bypasses that. That's what sudo is for. You're not going to be able to bypass using sudo, or some other means of working with root privileges.

Again...this is for *your* protection and not just to be an inconvenience. Understanding this is part of learning to work with an OS that isn't intrinsically single user.

User avatar
thagrol
Posts: 2229
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Sudo instructions to insert a directory within /home

Sat Dec 14, 2019 1:17 pm

W. H. Heydt wrote:
Fri Dec 13, 2019 8:38 pm
thagrol wrote:
Fri Dec 13, 2019 6:37 pm
You could do something like this:

Code: Select all

sudo mkdir /home/some_directory
sudo chmod a+rwx /home/some_driectory
A better choice for that second line would be:

Code: Select all

sudo chown <some_user_account> /home/<some_directory>
Well yes. But if you're doing that surely my last option is better: create a new user specfic for the use case you have in mind and set permissions apropriately.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

User avatar
thagrol
Posts: 2229
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Sudo instructions to insert a directory within /home

Sat Dec 14, 2019 1:49 pm

At the end of the day it's @Nathan.Rivard's pi. If he wants to break with convetion and standard practise that's his choice, however ill advised that me be.

My suspicion is that he comes from the windows world where you only really have one user plus an admin user. Raspbian (and most/all linux/unix systems) have many and many of them will be running processes at the same time. For example, my primarly development pi has 31* users but only one of those has a directory in /home. And can login.

The windows multi-user model has been tacked onto the single user model from ealier version which in turn came from the single user world of MS-DOS.

The linux model, on the other hand, came from the unix (and other OS) world where rather than computers being one per desk they were many desks to one computer. In that world there's an obvious need to restrict not only what users can do (or you risk them breaking things for everyone) but also to protect their data from being meddled with by other users.

A standardised file tree makes it much easier to train your users and admins and for them to transfer between machines.

As I opened with, it's your system so do things however you want to but be aware of the implications of your choices and that the less standard your way of doing things is, the less transferrable that knowledge is.

*: See the output of

Code: Select all

cat -n /etc/passwd
Appologies for the lecture but this stuff is important.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

gkaiseril
Posts: 679
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: Sudo instructions to insert a directory within /home

Sat Dec 14, 2019 2:29 pm

One might want to review all the various directories used by Raspbian and linux. There already exist a directory for shared user files, /user, The /home directory has the home directories for each individual user.

In the end the choice is up to the administrator or user and how that person wants to follow the standards or best practices. Yes, one can ignore them but if or when the developer's programs are to be moved to a public distribution adjusting things for general public will become additional work and a source for error.
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

hippy
Posts: 6755
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Sudo instructions to insert a directory within /home

Sat Dec 14, 2019 2:40 pm

thagrol wrote:
Sat Dec 14, 2019 1:49 pm
My suspicion is that he comes from the windows world where you only really have one user plus an admin user.
The Windows model has been much like the Linux model for a long time now; it's just that Windows users are more used to being the administrator or having superuser rights so don't notice it.

User avatar
thagrol
Posts: 2229
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Sudo instructions to insert a directory within /home

Sat Dec 14, 2019 2:59 pm

hippy wrote:
Sat Dec 14, 2019 2:40 pm
thagrol wrote:
Sat Dec 14, 2019 1:49 pm
My suspicion is that he comes from the windows world where you only really have one user plus an admin user.
The Windows model has been much like the Linux model for a long time now; it's just that Windows users are more used to being the administrator or having superuser rights so don't notice it.
Well, yes. Guess that's my age showing.

The move from FAT to NTFS seemed to be a large part of that, though UAC (the windows "sudo") came later.

Plus AIUI, windows doesn't do the seperate user for seperate processes thing that linux does. And how many domestic windows users actually have more than one user on their PC? Not many in the developed world I'd guess.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

hippy
Posts: 6755
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Sudo instructions to insert a directory within /home

Sat Dec 14, 2019 3:36 pm

thagrol wrote:
Sat Dec 14, 2019 2:59 pm
And how many domestic windows users actually have more than one user on their PC? Not many in the developed world I'd guess.
A few people I know have their family PC's configured with separate users for each family member but most people use their own PC or share a single user name. If only to avoid the login screen.

But I doubt that's any different to the Pi where most people will use "pi" and that's it. I expect most home users have never added a second user, disabled the "pi" account nor altered its password.

Return to “Troubleshooting”