- How can I give write-access of a folder to all users in linux?
- 8 Answers 8
- The common practice to share file for all users on the same machine? [duplicate]
- 2 Answers 2
- How to List Users in Linux
- Listing Users in Linux
- List Users with cat Command
- List Users with Terminal Pagers less and more
- List Users with awk Command
- List Users with getent Command
- Listing Normal and System users in Linux
How can I give write-access of a folder to all users in linux?
I installed apache2 on Ubuntu just now, and noticed that the /var/www folder is protected. I can just sudo everything but I would rather just give it write access. How can I do this? I tried sudo chmod 7777 /var/www but it didn’t work.
Is this a publicly accessible server, or does it have no direct connection to the internet? If the former it is important that you consider security decisions — servers on the internet are constantly under attack (have a look in your /var/log/messages or equivalent).
8 Answers 8
To best share with multiple users who should be able to write in /var/www , it should be assigned a common group. For example the default group for web content on Ubuntu and Debian is www-data . Make sure all the users who need write access to /var/www are in this group.
Then set the correct permissions on /var/www.
sudo chgrp -R www-data /var/www sudo chmod -R g+w /var/www
Additionally, you should make the directory and all directories below it «set GID», so that all new files and directories created under /var/www are owned by the www-data group.
sudo find /var/www -type d -exec chmod 2775 <> \;
Find all files in /var/www and add read and write permission for owner and group:
sudo find /var/www -type f -exec chmod ug+rw <> \;
You might have to log out and log back in to be able to make changes if you’re editing permission for your own account.
That is how you give access to it. It’s quicker to copy and paste the commands than try to navigate through a GUI file manager’s dialogs to do the same thing. Long term it helps you if you read the manual pages for chmod and chgrp, at least («man chmod»).
+1 for guid to force apache permissions. works well with umask of 027. If something needs writes access, it’s as easy as chmod g+w dir/
There’s a simpler way to do this, try doing this command.
Essentially, the chmod command alters permissions and the -R switch affects all users. Then it is simply giving the correct permissions to use.
You can also replicate what jtimberman suggested using access control lists. The setfacl command accepts -s to replace an existing ACL or -m to modify it; -R to make directory ACLs recursive; and -d to make the specified settings the default, which is useful if you’re anticipating forthcoming user accounts.
These just set the permissions as you would for the user, group, other, and mask using chmod:
setfacl -m u::rwx, g::r-x, o::---, m:rwx DIRECTORY
And this could be how you’d do it for a specified user or his/her group:
setfacl -m u:USERNAME:rwx, g:USERNAME:r-x DIRECTORY
And of course, the strength is that you can designate any specific user, multiple users, etc., all without having to modify your group settings. And unlike chmod, if you want some groupies to have access to one directory and other groupies to have access only to another, it’s actually possible with setfacl. Finally, to view a directory’s ACLs, run getfacl:
And you can specify -R to see the ACLs for subdirectories or -d to see the defaults.
The common practice to share file for all users on the same machine? [duplicate]
There is a server with several users. A user may want to read another user’s files (few gigabytes) and may want to put processed files in other’s directory. What’s the common practice to do it? I can think of create a /share folder and make it rwx to all. Is this the common practice?
An answer on Askubuntu recommends creating a directory under /home/share and details several ways to enable more or less writing permissions to files under that directory.
2 Answers 2
For occasional use, the common practice is that each user creates files in their own home directory. ~/pub is a common name of a directory for files all other users are supposed to be able access. If only a subset of users may access certain files, use groups or access control lists to manage permissions.
For more advanced use, when multiple users may work on the same file, use a version control system. There’s no really standard place to store the (master) repository; I’ve seen repositories under ~someuser/$project , /net/repositories/$project , /srv/repositories/$project , /var/www/$project , /home/$project , etc.
I think you are searching for /usr/local/share/ but it is hard to answer since this depends on what kind of file your are planning to «share» between users.
But if we are talking about office files or something like that maybe you should use use some kind of revision system like subversion or git. And then the users will have a checkout/clone in their homedir.
Update: A way to make this a little bit better could would be that every user gets it’s own subdir in the shared folder. He is allowed to write in his own folder but not the other subfolders. And all users are allowed to read from all the directories. That way you don’t have to think about file collisions if two users use the same filename, or deletes the colleges files by mistake.
Btw the idea behind /usr/ is described in the Filesystem Hierarchy Standard ( http://www.pathname.com/fhs/2.2/fhs-4.1.html )
-«/usr is shareable, read-only data.«
So I would probably use a dir in either /home/ or /var/ instead.
How to List Users in Linux
User management is a critical Linux system administration task. In large organizations, having insight into who has access to the system is crucial to correctly add users, remove users, and assign new user privileges.
This tutorial will show you how to list users on a Linux-based system. The guide provides four listing methods and explains essential concepts related to user administration.
Listing Users in Linux
Linux stores information about local users in the /etc/passwd file. Each line in the file contains information about a single user, including their username, user ID number (UID), home directory, and the login shell.
The following sections present multiple ways to access the data in /etc/passwd and list users on Linux distributions.
The commands used in the tutorial are:
Note: To display a list of the logged-on users and the information such as boot time, processes, hostnames, and more, use the who command.
List Users with cat Command
The cat command provides a straightforward way to list the contents of the /etc/passwd file.
The system outputs the entire file with all the users on the system.
To view the number of users only, pipe the output of the previous command to the wc command and make it count the number of lines:
The number of lines in /etc/passwd corresponds to the total number of users.
List Users with Terminal Pagers less and more
On systems with many users, it is useful to limit the /etc/passwd file output displayed at once. Use a terminal pager command, such as less or more , to browse through the file content line by line or page by page.
To open /etc/passwd using less , enter:
The first page of the file appears in the output. The list stops when it reaches the end of the terminal screen. Use the keyboard to navigate through the file.
Use more to get a similar result. This command is older and has a more limited set of functionalities:
List Users with awk Command
Use the awk command to list the usernames only, without additional information about each user. Since the data fields in /etc/passwd are separated by a colon symbol, the following syntax tells awk to output only the first field in each line:
Combine awk and less for a page-by-page view of the results.
List Users with getent Command
The getent command searches and displays system database entries. The searchable databases are listed in the /etc/nsswitch.conf file. By default, the file includes the passwd database.
List the entire contents of the passwd database by typing:
The output is the same as the output of the cat command.
However, you can use getent to look up specific users. To do so, use the following syntax:
If the user exists on the system, the command shows the related passwd entry line.
Listing Normal and System users in Linux
Linux-based systems have two types of users — system and normal users.
- System users are entities created by the system to run non-interactive processes, i.e., the processes that run in the background and do not require human interaction. The most important system user is root, which possesses administrative privileges.
- Normal users are human users created by root or another user with root privileges. Each normal user has a login shell and a home directory to store their files.
Both system and normal users in Linux have a unique user ID (UID) to identify them. System users have UIDs in the range from 0 (root user) to 999. Normal users typically receive UIDs from 1000 onwards, with each newly created user receiving the next smallest unused UID.
To check the UID range for normal users, use the grep command to search for the information stored in /etc/login.defs :
grep -E '^UID_MIN|^UID_MAX' /etc/login.defs
The output in this example shows that the smallest UID a normal user can receive is 1000, and the largest is 60000.
Use getent to search the passwd database by UID:
The output shows the user entry related to the UID.
Use UIDs in combination with getent to search for users in a range:
The command now lists all the users within the specified UID range.
This guide showed you how to list all Linux users, search for users, and find the number of Linux users in any Linux distribution.