LogoLogo
  • Home
  • Getting Started
  • Configuration
    • LinuxGSM Config
    • Game Server Config
    • Start Parameters
    • cronjobs
    • Running on Boot
    • Running Multiple Game Servers
    • IP Address Configuration
    • LinuxGSM Stats
  • Commands
    • install
    • start-stop-restart
    • monitor
    • test-alert
    • console
    • debug
    • update
    • check-update
    • force-update
    • validate
    • update-lgsm
    • backup
    • map-compressor
    • details
    • mods
    • skeleton
    • fastdl
    • change-password
  • Game Servers
    • 7 Days to Die
    • Arma 3
    • ARK: Survival Evolved
    • Call of Duty 4
    • Dont Starve Together
    • Counter-Strike 2
    • Counter-Strike: Global Offensive
    • Factorio
    • Garry's Mod
    • Insurgency: SandStorm
    • Killing Floor 2
    • Minecraft: Java Edition
    • Multi Theft Auto
    • Rust
    • Sven Co-op
    • Trackmania Nations Forever / Trackmania United Forever
    • TeamSpeak 3
    • Unreal Tournament 99
    • Unreal Tournament 2004
    • Unreal Tournament 3
    • Valheim
    • Xonotic
    • The Front [WIP]
  • Networking
    • IP Address
    • Ports
    • Source Engine
  • Alerts
    • Discord
    • Email
    • IFTTT
    • Pushbullet
    • Pushover
    • Rocket.Chat
    • Slack
    • Telegram
  • Dependencies
    • Java
    • tmux
    • jq
    • gamedig
    • glibc
  • Features
    • ANSI Colors
    • Stop Mode
    • Log Management
    • Message Display Time
  • SteamCMD
    • Steam Master Server
    • Game Server Login Token
    • Branch
    • LAN Discovery
    • Workshop
    • Error Codes
  • Linux
    • distro
    • ftp-scp
    • file-ownership
    • firewalls
    • network-interfaces
    • permissions
    • Symlinking and ln command
  • Troubleshooting
  • FAQ
  • Guides
    • Security
    • Make Webserver Case Insensitive
    • Sourcemod and Metamod:Source
  • Other
    • server-migration
    • basic-usage
    • brand
Powered by GitBook
On this page
  • Introduction
  • Check current ownership
  • Check ownership in the current directory:
  • Check ownership from all files and hidden files of any directory
  • All these commands require elevated privileges!
  • Change owner
  • Command
  • Group ownership
  • Command
  • Single file syntax
  • Recursive syntax (include sub files and directories)
  • User and group ownership
  • Command
  • Single file command
  • Recursive
Edit on GitHub
Export as PDF
  1. Linux

file-ownership

Introduction

Linux files and directories always belong to a user and group. That is what we call ownership. If this can be boring to new users, remember that this is a huge part of what makes Linux as secure as it is.

Check current ownership

Check ownership in the current directory:

ls -l

Example output:

ultimatebyte@game:~$ ls -l
total 32
drwxr-xr-x 5 ultimatebyte ultimatebyte 4096 Jan 29 22:26 lgsm
drwxr-xr-x 5 ultimatebyte ultimatebyte 4096 Jan 29 22:23 log
drwxr-xr-x 4 ultimatebyte ultimatebyte 4096 Jan 29 22:26 serverfiles
drwxr-xr-x 8 ultimatebyte ultimatebyte 4096 Jan 29 22:26 Steam
drwxr-xr-x 5 ultimatebyte ultimatebyte 4096 Jan 29 22:24 steamcmd
-rwxr-x--- 1 ultimatebyte ultimatebyte 5691 Jan 30 01:14 twserver

Syntax of the output is:

  • d for directory or - for file

  • user, then group, then others permissions

  • number specifies the number of links or directories inside of a directory

  • The user that owns the file, or directory

  • The group that file or directory belongs to

  • The size in bytes

  • The date of last modification

  • The name of the file

Check ownership from all files and hidden files of any directory

ls -al /path/to/file/or/dir

Sample output:

ultimatebyte@game:~$ ls -al /home/ultimatebyte
total 132
drwxr-xr-x 11 ultimatebyte ultimatebyte  4096 Feb  2 07:36 . # Ownership from the current given dir
drwxr-xr-x 22 root         root          4096 Feb  2 07:36 .. # Ownership from the parent dir
-rw-------  1 ultimatebyte ultimatebyte 49744 Feb 12 03:04 .bash_history
-rw-r--r--  1 ultimatebyte ultimatebyte   220 Apr 15  2016 .bash_logout
-rw-r--r--  1 ultimatebyte ultimatebyte  3515 Apr 15  2016 .bashrc
drwxr-xr-x  4 ultimatebyte ultimatebyte  4096 Jan 15 23:26 .config
drwxr-xr-x  5 ultimatebyte ultimatebyte  4096 Jan 29 22:26 lgsm
drwxr-xr-x  3 ultimatebyte ultimatebyte  4096 Jan 14 18:10 .local
drwxr-xr-x  5 ultimatebyte ultimatebyte  4096 Jan 29 22:23 log
-rw-------  1 ultimatebyte ultimatebyte  1005 Jan 30 01:14 .nano_history
-rw-r--r--  1 ultimatebyte ultimatebyte   675 Apr 15  2016 .profile
-rw-r--r--  1 ultimatebyte ultimatebyte    66 Sep  1 17:43 .selected_editor
drwxr-xr-x  4 ultimatebyte ultimatebyte  4096 Jan 29 22:26 serverfiles
drwxr-xr-x  3 ultimatebyte ultimatebyte  4096 Jan 15 01:40 .steam
drwxr-xr-x  8 ultimatebyte ultimatebyte  4096 Jan 29 22:26 Steam
drwxr-xr-x  5 ultimatebyte ultimatebyte  4096 Jan 29 22:24 steamcmd
-rwxr-x---  1 ultimatebyte ultimatebyte  5691 Jan 30 01:14 twserver
-rw-r--r--  1 ultimatebyte ultimatebyte    29 Jan 30 02:17 .tw-server.lock

All these commands require elevated privileges!

Change owner

Change owner from files or directories

Command

chown

As usual, chown --help will provide you with all available arguments

Single file syntax

chown newowner /path/to/file/or/directory

Recursive syntax (include sub files and directories)

chown -R newowner /path/to/directory

Example

chown -R myuser /home/myuser

Group ownership

Change group ownership on files or directories

Command

chgrp

As usual, chgrp --help will provide you with all available arguments

Single file syntax

chgrp newgroup /path/to/dir/or/file

Recursive syntax (include sub files and directories)

chgrp -R newgroup /path/to/dir/

User and group ownership

Change user and/or ownership for files and directories at the same time

Command

chown

As usual, chown --help will provide you with all available arguments

Single file command

chown user:group /path/to/dir/or/file

Recursive

chown -R user:group /path/to/dir

Example:

chown -R myuser:myuser /home/myuser

Previousftp-scpNextfirewalls

Last updated 6 years ago