Skip to content

Sudo and home folder

wordpress meta

title: 'Sudo and home folder'
date: '2018-08-14T08:45:54-05:00'
status: publish
permalink: /sudo-and-home-folder
author: admin
excerpt: ''
type: post
id: 1257
category:
    - sudo
tag: []
post_format: []

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

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