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

Here you'll find a place for solutions and hints.

Please use one of the support subforums below for questions or if you have any issues and need support.

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

Postby Ken-Bergen » Jun 12th, '12, 09:54

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.
Last edited by doktor5000 on Aug 19th, '12, 11:35, edited 1 time in total.
Reason: adjusted thread title
Ken
Ken-Bergen
 
Posts: 1019
Joined: Mar 30th, '11, 02:45
Location: Chilliwack, BC, Canada

Re: su - Rant!

Postby maat » Jun 12th, '12, 12:12

I'd like to learn a solution for that :)
maat
 
Posts: 307
Joined: Feb 13th, '11, 00:23

Re: su - Rant!

Postby alf » Jun 12th, '12, 12:29

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'
for windows problems reboot; for linux problems be root
alf
 
Posts: 326
Joined: Apr 1st, '11, 23:07
Location: DE Paderborn

Re: su - Rant!

Postby ah7013 » Jun 12th, '12, 13:05

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.
Mageia 2 x86_64, KDE 4.8.5 on a Thinkpad Edge E520 - Intel Core i7-2640M 2.8GHZ, 16GB DDR3 RAM 1333MHz
Mageia 2 x86_64, KDE 4.8.5 on a Dell Studio 1555 - Intel Core 2 Duo T6600 2.2GHz, 8GB DDR2 RAM 800MHz
User avatar
ah7013
 
Posts: 74
Joined: Apr 9th, '11, 05:02
Location: Adelaide, Australia

Re: su - Rant!

Postby Ken-Bergen » Jun 12th, '12, 20:48

Thank you ah7013 that worked like a charm.
Ken
Ken-Bergen
 
Posts: 1019
Joined: Mar 30th, '11, 02:45
Location: Chilliwack, BC, Canada

Re: su - Rant!

Postby doktor5000 » Jun 12th, '12, 23:50

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
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: su - Rant!

Postby jankusanagi » Jun 13th, '12, 00:10

I use "su" by itself, no dash, and it works as you intend.
Use Jabber/XMPP for free and decentralized instant communication,
Pump.io for free and decentralized social networking.

Dianara developer.
User avatar
jankusanagi
 
Posts: 13
Joined: Mar 30th, '11, 14:03
Location: Earth

Re: su - Rant!

Postby doktor5000 » Jun 13th, '12, 00:37

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.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: su - Rant!

Postby jankusanagi » Jun 13th, '12, 02:02

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
Use Jabber/XMPP for free and decentralized instant communication,
Pump.io for free and decentralized social networking.

Dianara developer.
User avatar
jankusanagi
 
Posts: 13
Joined: Mar 30th, '11, 14:03
Location: Earth

Re: su - Rant!

Postby yankee495 » Jun 13th, '12, 05:04

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.
There are 10 types of people, those who understand binary & those who don't.
Main Desktop
http://www.overclock.net/lists/display/view/id/3960066
yankee495
 
Posts: 433
Joined: May 25th, '12, 13:10
Location: Carthage, Mo. USA

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

Postby Ken-Bergen » Sep 11th, '12, 23:59

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.
Ken
Ken-Bergen
 
Posts: 1019
Joined: Mar 30th, '11, 02:45
Location: Chilliwack, BC, Canada

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

Postby jkerr82508 » Sep 12th, '12, 00:36

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
jkerr82508
 
Posts: 946
Joined: Mar 26th, '11, 01:34
Location: Fife, Scotland

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

Postby viking60 » Sep 21st, '12, 18:36

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.
Image Flexibility is good and inxi is good... install both!
User avatar
viking60
 
Posts: 255
Joined: Mar 19th, '11, 22:26

Re: su - Rant!

Postby Silver22 » Sep 28th, '14, 03:43

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
MOBO: ASUS|F2A85-V PRO A85 FM2 R
PROCESSOR: AMD A10-5800K APU with Radeon(tm) HD 3.8G 4M FM2 R
MEM: 8X2 G.SKILL F3-12800CL9D-8GBRL
HD: Segate 250 gig
VIDEO CARD: ONBOARD AMD/ATI TRINITY [RADEON 7660D]
Silver22
 
Posts: 50
Joined: Aug 20th, '12, 15:35
Location: Georgia

Re: su - Rant!

Postby jkerr82508 » Sep 28th, '14, 09:33

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
jkerr82508
 
Posts: 946
Joined: Mar 26th, '11, 01:34
Location: Fife, Scotland

Re: su - Rant!

Postby Silver22 » Sep 28th, '14, 16:26

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
MOBO: ASUS|F2A85-V PRO A85 FM2 R
PROCESSOR: AMD A10-5800K APU with Radeon(tm) HD 3.8G 4M FM2 R
MEM: 8X2 G.SKILL F3-12800CL9D-8GBRL
HD: Segate 250 gig
VIDEO CARD: ONBOARD AMD/ATI TRINITY [RADEON 7660D]
Silver22
 
Posts: 50
Joined: Aug 20th, '12, 15:35
Location: Georgia


Return to The magician suggests...

Who is online

Users browsing this forum: No registered users and 1 guest

cron