buymeasoda RefDocs
  • Overview
  • General
    • Android
    • Apache
    • Fish
    • Git
    • Github
    • Gmail
    • Homebrew
    • iOS
    • iTerm
    • MacOS
    • MacPorts
    • Mamp
    • Media
    • Mercurial
    • MySQL
    • Node
    • npm
    • nvm
    • Obsidian
    • PHP
    • React Native
    • Rust
    • Server
    • Slack
    • Sourcegraph
    • Tools
    • Vim
    • VS Code
    • Yarn
  • Unix
    • Checksum and hash utilities
    • Command line history
    • Command line keyboard shortcuts
    • Compress files and folders
    • Crontab
    • Diff files and folders
    • Disk usage and file sizes
    • Find and search files
    • Firewall configuration
    • Help and manual pages
    • HostName and Local HostName for Mac OSX
    • Navigating the file system
    • Network, domains and routing
    • Run and manage background tasks
    • Secure FTP SFTP and Secure Copy SCP
    • Secure Shell SSH
    • Sync files and folders
    • System and process management
    • System and user information
    • Useful characters
    • Useful commands
    • User, file and group permissions
    • Working with cURL
    • Working with files and directories
    • Working with text
Powered by GitBook
On this page
  • Info
  • Sudo
  • Switch users
  • Managing users
  • File permissions
  • Set permissions with assigment
  • Alter some permission with plus and minus
  • Use -R to set permissions recursively
  • Set user / group for new files
  • Managing groups and owners
  • Cleaning up file permissions
  1. Unix

User, file and group permissions

Info

Show all groups a user belongs to

groups <user>

Show primary groups for user

id <user>

Sudo

Perform a command as the super user

sudo <command>

Switch users

Switch to specific user

su <user>

Switch to root or specific user and load user profile (CTRL + d to exit user mode)

su -
su - <user>

Managing users

Create a new user

adduser <username>

Change password for active user

passwd

File permissions

Change file mode and access control

chmod <permissions> <file>

Permission types

r = read
w = write
x = execute

Numerical values

r = 4
w = 2
x = 1

Permission groups

u = user
g = group
o = other
a = all (sets u, g and o)

Set permissions with assigment

Set user to rwx, group to rw and other to r

chmod u=rwx,g=rw,o=r <file>

Set u to rwx, group and other to r

chmod u=rwx,go=r <file>

Alter some permission with plus and minus

Add write permissions to user group

chmod g+w <file>

Remove read and write permission from other group

chmod o-rw <file>

Add execute for user, remove write for group, remove rwx for other

chmod u+x,g-w,o-rwx

Use -R to set permissions recursively

Set group to read and write for the directory and all sub files and folders

chmod -R g=rw <dir>

Set user / group for new files

Set group automatically when creating new files within <dir> via the g+s SETGID (SET Group ID) flag

chmod g+s <dir>

Remove setting group automatically for new files within <dir> by removing set group flag

chmod g-s <dir>

Managing groups and owners

List available groups

less /etc/group

Modify a user (usermod) and add (-a) them to a group (-G)

usermod -a -G <group> <username>

Change file group associated with the file permissions

chgrp <group> <file>

Change file owner

chown <user> <file>

Cleaning up file permissions

Find files with permission set to 777 and change them to default 644

find . -type f -perm 777 -print0 | xargs -0 chmod 644

Find directories with permission set to 777 and change them to default 755

find . -type d -perm 777 -print0 | xargs -0 chmod 755

Unlock all locked files found under the current directory

chflags -R nouchg *
PreviousUseful commandsNextWorking with cURL

Last updated 1 year ago