Page 1 of 1

[SOLUTION] Using "su -" without changing directory/Path

PostPosted: Jun 12th, '12, 09:54
by Ken-Bergen
Is it possible to use
Code: Select all
su -
without the seemingly built in
Code: Select all
cd /root
I often use Dolphin to find a file I wish to edit, then right click to open a terminal. I then su to root but then have to
Code: Select all
export $(dbus-launch)
in order to open a graphical editor such as kwrite.
If I use su - I get the cd /root then have to cd back to where I was.
I realize this behaviour is likely built in upstream but if anyone has a simple work around I'd like to hear it.

Re: su - Rant!

PostPosted: Jun 12th, '12, 12:12
by maat
I'd like to learn a solution for that :)

Re: su - Rant!

PostPosted: Jun 12th, '12, 12:29
by alf
Ken-Bergen wrote:I realize this behaviour is likely built in upstream but if anyone has a simple work around I'd like to hear it.

Can maybe done by crating an alias like this
Code: Select all
alias ss='homedir=~ && su - && cd $homedir'

Re: su - Rant!

PostPosted: Jun 12th, '12, 13:05
by ah7013
This worked for me:
Code: Select all
alias cdsu='su - -c "cd \"$PWD\" && bash"'

Then just run cdsu (or whatever else you want to call the alias). A bit ugly but it should work.

Re: su - Rant!

PostPosted: Jun 12th, '12, 20:48
by Ken-Bergen
Thank you ah7013 that worked like a charm.

Re: su - Rant!

PostPosted: Jun 12th, '12, 23:50
by doktor5000
Well i just use sudo for that, works just the same. But i won't go into details about that setup or you'll beat me ... :o

Re: su - Rant!

PostPosted: Jun 13th, '12, 00:10
by jankusanagi
I use "su" by itself, no dash, and it works as you intend.

Re: su - Rant!

PostPosted: Jun 13th, '12, 00:37
by doktor5000
This is not really of interest, please see the second part of Ken's original post. su - initializes full environment, the same as opening a login shell.
Try to start any graphical program after you used just su.

Re: su - Rant!

PostPosted: Jun 13th, '12, 02:02
by jankusanagi
True, true... but to start graphical programs there is kdesu/gksu/gksudo.

I have a policy of not starting GUI's as root if there is another way. A matter of taste, I guess.
So, to me, "su" by itself is just the same, so I forget :P

Re: su - Rant!

PostPosted: Jun 13th, '12, 05:04
by yankee495
There is a package called kde root actions that gives you a right click root actions including opening a file in kwrite.

It works in Dolphin & Konquerur.

Re: [SOLUTION] Using "su -" without changing directory/Path

PostPosted: Sep 11th, '12, 23:59
by Ken-Bergen
Just a note and someone please correct me if I'm wrong. ;)

An alias created at the command line does not seem to survive a logout or reboot.
Adding it to ~/.bashrc recreates the alias at login.

Re: [SOLUTION] Using "su -" without changing directory/Path

PostPosted: Sep 12th, '12, 00:36
by jkerr82508
It survives only for the current bash "session". Thus it will only work in the current terminal. Open a new terminal, or just a new tab in an existing terminal, and the alias will not be found in the new terminal or tab. IIRC, to make it permanent for all users, it can be added to /etc/profile.d/xxalias.sh

Jim

Re: [SOLUTION] Using "su -" without changing directory/Path

PostPosted: Sep 21st, '12, 18:36
by viking60
Or just put all your aliases in ~/.alias
I think you have to call it from .bashrc so I added this code to .bashrc

Code: Select all
# getting aliases from ~/.alias
if [ -f .alias ]; then
        . .alias
    fi

After that any alias I add to ~/.alias works all the time.

Re: su - Rant!

PostPosted: Sep 28th, '14, 03:43
by Silver22
yankee495 wrote:There is a package called kde root actions that gives you a right click root actions including opening a file in kwrite.

It works in Dolphin & Konquerur.


I needed to use dolphin as root today and had to give up and open pclinuxos which can be started and used as root. Shouldn't have had to go to this much trouble but nothing else I tried would allow me to do what I needed done. To add insult to injury, I could find nothing in the repo called kde root actions or anything remotely similar. The good news is it gave me a chance to bang my head up against the wall for a while :D

Re: su - Rant!

PostPosted: Sep 28th, '14, 09:33
by jkerr82508
Silver22 wrote: I could find nothing in the repo called kde root actions or anything remotely similar.

Package names never include spaces:
Code: Select all
$ urpmq --fuzzy kde-root
kde-rootactions-servicemenu

Alternatively just search for kde-root in the GUI Software Manager.

If you want to run dolphin as root:
Code: Select all
$ su -
# dolphin

Jim

Re: su - Rant!

PostPosted: Sep 28th, '14, 16:26
by Silver22
jkerr82508 wrote:Package names never include spaces:
Code: Select all
$ urpmq --fuzzy kde-root
kde-rootactions-servicemenu

Alternatively just search for kde-root in the GUI Software Manager.


Got it. The hyphens threw me off.

If you want to run dolphin as root:
Code: Select all
$ su -
# dolphin

Jim


Thanks. Saved info for future reference.

Bill