Riaan's SysAdmin Blog

My tips, howtos, gotchas, snippets and stuff. Use at your own risk!


Sudo and home folder

I suspect behavior of setting $HOME when using sudo may differ between Linux flavors. As most modern Unix operating systems discourage using the root account and promote using sudo, I have mostly always used "sudo -s". I expect that my shell then will reference /root as my home folder($HOME).

I have a backup script I run in the root crontab but I had a tricky issue with restic/rclone where running the script from the command line worked but from cron failed silently. After some debugging I noticed rclone was using the rclone.conf from my regular user home folder when run in the command line and not from root account's home folder.

So I noticed that "sudo -i" was working as opposed to "sudo -s" failing. In this Ubuntu 18.04 client I am working on the behavior of sudo differed from what I was used to. See below:

rrosso@u1804:~$ sudo -i
root@u1804:~# echo $HOME

root@u1804:~# logout
rrosso@u1804:~$ sudo -s
root@u1804:~# echo $HOME


Bio Info for Riaan