File Permissions | SpiffberryPi

+ DEV SERVER



 sudo adduser --disabled-password git 

p>You've created a user with a “disabled password”, meaning that there is no password that will let you log in as this used. This is different from creating a user that anyone can log in as without supplying a password, which is achieved by specifying an empty password and is very rarely useful.

In order to execute commands as such “system” users who don't log in normally, you need to hop via the root account:

su -c 'su git -c "git init"'

or

sudo -u git git init

If you want certain users to be able to run commands as the git user without letting them run commands as root, set up sudo (run visudo as root and add a line like %gitters ALL = (git) ALL)

Ubuntu Permissions

https://help.ubuntu.com/community/FilePermissions


Type 

sudo chmod a+rwx /path/to/file

into the terminal, replacing “/path/to/file” with the file you want to give permissions to everyone for, and press “Enter.” You can also use the command 

sudo chmod -R a+rwx /path/to/folder

to give permissions to the selected folder and its files. 

Ubuntu, like other Linux distributions, restricts access to files and system settings by default. Each user account has read and write access to its own files and read access to some system files. Other user accounts can’t view another user account’s files. You can give file or folder permissions to all users using the “chmod” command.

The first user account you create when you install Ubuntu has administrative access, which allows you to enter your password and use system programs. You can grant administrative permissions to other user accounts from the User Accounts window. Keep reading to learn how to change folder and file permissions in Linux with examples as well as change account levels.

File and Folder Permission in Ubuntu

Whether you want to change permissions for a single file or a folder and everything inside it using the command line, you should first open a terminal window by clicking the "Activities" option at the top left corner of the screen, typing “Terminal” into the search box that appears and pressing “Enter.” You'll use your root permissions at the command line by preceding a command with “sudo”.

Type “sudo chmod a+rwx /path/to/file” into the terminal, replacing “/path/to/file” with the file you want to give permissions to everyone for, and press “Enter.” You can also use the command “sudo chmod -R a+rwx /path/to/folder” to give permissions to the selected folder and its files. The University Corporation for Atmospheric Research warns you should omit the “x” from either command if you don’t want the files to be executable. You'll need to enter your password to proceed with the changes since Ubuntu requires this to use elevated permissions.

If you'd rather not use Terminal, you can also change the file or folder permissions in Ubuntu from the file manager window by right-clicking it, selecting “Properties” and clicking the “Permissions” tab in the properties window that appears. However, you can only use this window to change a file’s permissions if your user account owns the file.

Giving Users Administrative Access

If you want to change a whole user's permissions rather than give permission to a folder in Linux, you should log in to the Ubuntu desktop as a user with administrative permissions. Ubuntu says you can then click the "Activities" button and search for "Users." Select the "Users" option when it appears and then proceed to use the "Unlock" button to unlock the settings using your administrator password

Select the account you want to give permissions to in the list, click the “Account Type” box at the right side of the window and select “Administrator.” If the user is currently logged in, they'll have to log out and log back in to receive the updated permissions.

The new administrative user will be able to use the "sudo" command to change permissions and do other actions. For example, they can use “sudo apt-get update” to download updated information about available software packages.

Warning About Permissions

Be aware that granting permissions to all users is dangerous. You shouldn't grant permissions for system files or folders to all user accounts. The default permissions protect your system.


https://www.dummies.com/computers/raspberry-pi/working-with-file-permissions-on-your-raspberry-pi/

Working with File Permissions on Your Raspberry Pi

img

By Richard Wentk

There’s no way around file permissions on the Raspberry Pi. You have to understand them and know how to use them, or you won’t get much done with Linux.

You need to know a handful of commands for working with permissions. The following table shows a list.

Command What It Does
ls -l Lists files with permissions
chmod Changes file permissions
chown Changes the file owner
groups Checks the users in a group
useradd Adds a user to a group
chgrp Changes the file group

You can use the –l switch to check permissions them when you use the ls command to list the files in a folder. But what if you want to change them?

Using chmod

To use chmod to change file permissions, you have to tell it three things:

  • Who you’re setting permissions for
  • How you’re setting them (there’s more than one way . . .)
  • What you’re setting them to

An example command looks like this:

sudo chmod a+w filename-or-full-filepath

In the following sections, this command is broken down. You have to start the command with sudo. Otherwise, you can’t change permissions for files you don’t have permissions for.

Selecting a who

The following table shows you how to pick a letter to tell the command who you’re setting the permissions for.

Letter What It Means
u The owner of the file
g The file group
o Everyone who isn’t the owner or the group
a Everyone at all — no exceptions

Selecting a how

Next, you specify how you want to change the permissions. The following table has the details.

Letter What It Means
+ Adds/turns on a permission
Removes/turns off a permission
= Ignores the current permissions and sets some new ones

The + and – options change the permissions that exist already. Use them if you want to add or remove a permission. For example, you can change the write permission only and leave the read and execute permissions alone.

The = option changes all the permissions at once. Use it when you don’t care about existing permissions, and you just want to swoop in and set them all how you want.

Selecting a what

The following table shows you which letters to type to select the different permissions. This part is easy.

Letter Read r
r Read permission
w Write permission
x Execute permission
X Special magic execute permission for folders

Most of these do what you expect, but execute has some special features:

  • You can look inside a folder only if you can execute it. You may think read would be enough, but it isn’t.
  • You can rename a file only if you can execute it. You may think write would be enough, but it isn’t.
  • As long as you can read a file, you can run it as code if it gets passed to some other app. You may think you need execute, but you don’t.

For example, if you have permission to read a file, you can run it as Python code because you’re actually executing Python first. Python reads the file, so it’s Python’s permissions that matter.

You need the execute permission only if the file is a self-contained app.

Confused? Probably. There’s no simple way to make sense of these special cases. You just have to think them through, remember them, and say “Huh” a lot when you forget them, until you check online and remind yourself.

If you’re trying to make software work together — for example, if you’re trying to use Python to create a web page for you — and you’re getting nothing, it’s a good bet the permissions aren’t right.

Sometimes permissions fail silently. Nothing appears on the screen. Stuff just doesn’t work, and you have no idea why. As a rule, when something doesn’t work and you have no idea, check the permissions first.

Putting it all together

Permissions are complicated, so you need to practice them. You probably won’t remember them otherwise.

Here’s a simple example. Say that you want to set permissions so that everyone who uses your Pi can write a file. Can you work out what the command should be? Assume that everyone can read it already.

It should look like this:

sudo chmod a+w filename-or-full-filepath

The following figure shows a before-and-after so that you can see how this command changes the permissions string when you use the ls command. After the command, everyone can edit the file.

image0.jpg

If you want to set multiple permissions, put them together like this:

sudo chmod a+rwx filename-or-full-filepath

You don’t need to use sudo to change the permissions on the files you own, so you can usually do whatever you like to files in your home directory. But if you’re trying to work with files elsewhere in your Pi, you definitely need sudo.

Using numbers

Sometimes permissions look like numbers. For example, blog articles and books sometimes tell you to set the permissions on a file to 777 or 644 or some other number.

Numbers are just a quicker and more compact way to define ­permissions. They’re easier to remember than a long row of letters. They’re also quicker to type.

But what do they mean? The first number sets your personal permission, the second number is the group permission, and the third number is the everyone else permission. So this is really just another way to write rwx three times.

The following table shows you how to convert between a three-letter permission string into a single number.

Number Read r Write w Execute x
7 r w x
6 r w
5 r x
4 r
3 w x
2 w
1 x
0

Some examples:

744 = rwxr--r--
777 = rwxrwxrwx
600 = rw-------

You can use the numbers instead of the letters in chmod, like this:

sudo chmod 644 filename-or-full-filepath

This sets the permissions to

rw-r--r-

Using the –R switch

If you want to change all the permissions inside a directory, you can change them for every file by hand — which can take a very long time.

Save yourself the effort with the –R switch. You can use it to change all the permissions for all the files inside a folder with a single command. To use it, include –R somewhere in the command when you type it.

Scroll to Top