1. Home
  2. Terminal Access
  3. Elevating privileges with sudo

Elevating privileges with sudo

Overview

Newer platforms, v6+, provide limited sudo support that allows you to remove, copy, and change ownership of files with elevated permissions (root). Depending upon the platform version, either  rm (v6) or rm, cp, and chown (v6.5+) commands are available.

Usage

sudo follows a general syntax: sudo command arguments. Certain commands have restrictions on what arguments can be used. sudo may only be used within the terminal and requires you to enter your password to confirm intention.

rm

rm is used to remove files. Any file may be removed, including system files on your account, so be cautious on usage! There are no restrictions on usage.

Example: sudo rm -rf /home/bob/bobswebsite.com

cp

available on v6.5+ platforms only

copy a file or set of files from a source to destination path. cp may be invoked without any flags or with -dR:

Example: cp myfile.txt mynewfile.txt

Example: cp -dR /home/bob/bobswebsite.com /var/www/bobstaging
Copy contents of bobswebsite.com to /var/www/bobstaging, which may be an addon domain or subdomain to test changes to bobswebsite.com

Limitations

  • any system file copied will be inherited towards the account storage usage
  • optionally accept the recursive (-R) flag and symlink deference (-d)
  • may not accept any other flags

chown

available on v6.5+ platforms only

Change ownership of a file or set of files.

Example: chown -R myadmin /home/bob/bobsmysite
Change ownership of bobsmysite, recursively to user “myadmin” for easy file management by myadmin

Example: chown apache /var/www/wp/wp-config.php
Change ownership of wp-config.php in wp/, a WordPress directory, so the web server may write to it during a configuration change.

Limitations

  • optionally accept the recursive flag (-R) to change ownership of all files in a directory
  • may not accept any other flags
  • may not alter group ownership (newuser:root is illegal)
  • must use an absolute path, e.g. chown newuser /var/www/myfile
    • the absolute path may reside within /var or /home only
    • the path may not traverse directories, e.g. /var/../root

Updated on July 8, 2019

Was this article helpful?

Related Articles