Run Commands Without Login Into User Shell
-
Linux
CommandLine
CommandOfTheDay
Bash
Sudo
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.