When I do su - to get to root, my current directory is set to root's home. Is there anyway to keep the current directory that I was in, much like sudo -s. Or is the answer to use sudo?
feedback
|
|
It's always better to use sudo, if possible, because then you don't need to know (or give someone) root's password. Set the root password to something long and horrible and then lock it in a safe. If you want to deny someone access later, you just remove their access to sudo, rather than having to teach everyone else a new root password. However - you don't need to use the '-' parameter if you don't want to. You will get a shell as root, it will just not be a login shell (so it will not run root's .profile.) | ||||
|
feedback
|
|
I agree that sudo is almost always a better answer but to answer the other part of the question... The '-' in 'su -' indicates that you want to emulate a superuser login, rather than just run with superuser priviledges. If you use plain 'su' rather than 'su -' you will stay in the same directory; however you will also be running in the same environment so may need to modify your path to access some admin commands. | |||
|
feedback
|
|
If you use
Or just use sudo, it's got a lot of other advantages. Or ssh keys. | |||
|
feedback
|
|
You should definitely use sudo.
That will keep you in the folder when you change to root. | ||||
feedback
|
|
Use sudo :). Seriously, you don't need su. 'sudo' is better as you only use it for privileged commands and can help avoid mistakes. You also get accountability. | |||
|
feedback
|
|
If you use "su" it does an interactive shell. This is the same as "sudo -s". "su -" creates a login shell, which will override the environment. "sudo -i" is the equivilent with sudo. If you are trying to get an interactive shell, you should always use the sudo -i (or su -) form, or it's possible to end up with weird file permissions in a user's home directory. | |||
|
feedback
|
|
you must modify the source of su to have this job done. there is a chdir call in a procedure of initialize envoironment varibles. comment out those statesments included that call. and now, you can do "su -" but keeps the current directory. | |||
|
feedback
|