Run Commands Without Login Into User Shell

Overview

  • Mostly While setting up web server, I was run multiple commands as root user.
  • After that I realize I’ve to change ownership of web root :(
  • By using following command we can directly create directory, copy files with given username instead of root user.

Syntax

$ sudo -H -u <USERNAME> <COMMAND>

Examples

$ sudo -H -u mitesh mkdir ~mitesh/bin
$ sudo ls -ld ~mitesh/bin
drwxr-xr-x 2 mitesh mitesh 4096 Jul  8 20:32 /home/mitesh/bin


Newsletter

Get updated when I create new content.
Unsubscribe whenever. Never any spam.

Note

I'm Tama. I turn down every ad, affiliate, and sponsor request I get. I write free resources that help people. If you enjoy my content, please consider supporting what I do.

Support my work