Stay at same working directory when changing to sudo

When working with the command line, I usually transform to sudo making use of sudo -i. Nonetheless, my functioning directory adjustments instantly to /root. I never ever intend to go there ; I intend to remain where I was! Just how can I attain this?

37
2022-06-07 14:37:28
Source Share
Answers: 1

You can make use of sudo -s rather, it would certainly not transform your existing directory to /root, though several of your environment variables would certainly not be those of origin.

This page from the Ubuntu Forums has a wonderful recap:

Summary of the differences found   
                                               corrupted by user's 
                HOME=/root      uses root's PATH     env vars
sudo -i         Y               Y[2]                 N
sudo -s         N               Y[2]                 Y
sudo bash       N               Y[2]                 Y
sudo su         Y               N[1]                 Y

This web page from from Ubuntu is documents has far more background information on sudo.

40
2022-06-07 15:11:02
Source