LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-04-2019, 03:21 AM   #1
Craftman
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Rep: Reputation: Disabled
How to I change su - root default location?


Hi All,

I'm new to Linux and current using OracleLinux 6.8

Question is how can I change my root or other user account default directory to my bespoke diectory after when I execute "su - __"
 
Old 04-04-2019, 03:32 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
su - brings you to the new user’s home directory. I don’t think this can be changed, so just use the cd command after su.
 
1 members found this post helpful.
Old 04-04-2019, 03:48 AM   #3
Craftman
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
Oh, as I was hopping if I can "su - root" to my chroot directory.

Does /etc/profile affect the login path?
 
Old 04-04-2019, 04:21 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You can change HOME in profile, but this doesn’t affect your current directory. You can however put a cd command into the profile.

I am not sure if you are asking the right questions. What do you want to achieve? Go to jail immediately at logon? Again I am not smarter than Google, but perhaps this helps: https://askubuntu.com/questions/5477...users-on-login.
 
Old 04-04-2019, 04:28 AM   #5
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,521

Rep: Reputation: Disabled
Normally, when you use su, you need to enter the root password, & then you will have root powers in/from your home directory.

When you use "su - root" you will be the root user in the /root directory.

Last edited by fatmac; 04-04-2019 at 04:32 AM.
 
Old 04-04-2019, 04:56 AM   #6
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by Craftman View Post
Oh, as I was hopping if I can "su - root" to my chroot directory.

Does /etc/profile affect the login path?
I think you're mixing up the user root, which you can become with the su (Switch User) command, with the root directory (/), which can be changed by chroot.
They're two quite different things.

The root directory normally is /, for all users, but after a chroot another directory becomes a new root and directories outside of the tree below that cannot be seen or reached anymore. It doesn't have anything to do with which user you are.
 
Old 04-04-2019, 05:01 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
su is a tool. What you wish is something else, su cannot do that for you. Changing any account do achieve this is not a really good approach. If you need a tool to do that I think you need to implement it (actually you need to write a small shell script).
 
Old 04-04-2019, 02:18 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
If you are in your chroot directory
Code:
su
(without the -) will give you root privileges in that directory.

As has been said the - causes the new user's environment to be loaded, which also causes a change to root's home directory, which is /root on my systems. If you don't want to change directories when you su, leave off the -

Note: If you're changing to another non-privileged user, leaving off the - will likely leave you in a state where you can't read or write the directory you're in.

Last edited by scasey; 04-04-2019 at 02:21 PM.
 
Old 04-04-2019, 08:40 PM   #9
Craftman
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
What I'm trying to achieve is to lock my current root account in chroot after I "su - root" from normal user account.

Example:
I login as a normal user "Alex" using putty.
In the current session when I key in "su - root". It will prompt for root password.
After which it will automatically go straight into my chroot.

Hi Pan64, do have a guide to write shell script to to implement it?
 
Old 04-04-2019, 08:46 PM   #10
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Quote:
Originally Posted by Craftman View Post
What I'm trying to achieve is to lock my current root account in chroot after I "su - root" from normal user account.

Example:
I login as a normal user "Alex" using putty.
In the current session when I key in "su - root". It will prompt for root password.
After which it will automatically go straight into my chroot.
I'm pretty sure you can't lock down the superuser that way, or any way. root can do anything.
As I said, leaving the - off will leave you wherever you are when you su, but then you'll be root and can go anywhere you want.

What, exactly, are you trying to accomplish? By that I mean, why do you want to do as you've asked?

Last edited by scasey; 04-04-2019 at 08:50 PM.
 
Old 04-04-2019, 09:14 PM   #11
Craftman
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
My aim is to trap root account in chroot.
I'm succeeded by using "ssh root@localhost" and it will login directly to my chroot since I've already config my directory and edited sshd_config.

Now I trying to do the same but by using su or sudo but none succeed.

Last edited by Craftman; 04-04-2019 at 09:59 PM.
 
Old 04-04-2019, 09:55 PM   #12
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,784

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
It is trivial for root to escape from a chroot jail. Easiest way is to simply move the jail to a subdirectory of your current location, and thus you are no longer inside it.
 
1 members found this post helpful.
Old 04-05-2019, 12:26 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
Quote:
Originally Posted by Craftman View Post
My aim is to trap root account in chroot.
No, that is nonsense. Root is the account which can do anything. You cannot restrict it (or you may damage the whole system by that).
 
1 members found this post helpful.
Old 04-05-2019, 03:39 AM   #14
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by Craftman View Post
What I'm trying to achieve is to lock my current root account in chroot after I "su - root" from normal user account.
I think it’s easier to simply disable su for normal accounts. See /etc/pam.d/su; you need to remove the comment in front of a single line to restrict su to members of group wheel.
 
Old 04-08-2019, 01:41 AM   #15
Craftman
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
As there is a security scanning software inplace in my organisation.
-ssh to root (need to be block)
-so I'm trying to do a work around which is ssh to another account and then su to root.

I already completed configuring my chroot.
Just that I want it whenever I "su root" it will automatic go into my chroot.

Which I'm not sure if its do able
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Google I/O Android News: Location, Location, Location (Plus Cloud Messaging and Bluetooth) LXer Syndicated Linux News 0 06-05-2013 01:00 PM
change grub boot order, all instructions say change default, but I don't see default mhg Linux - Newbie 5 11-09-2008 10:01 AM
change default location of sendmail users mailbox tanveer Linux - Server 4 05-03-2007 11:42 PM
location, location, location! mermxx LQ Suggestions & Feedback 9 09-25-2004 03:08 AM
how to change the default mail delivery location mnisski Linux - General 3 10-21-2003 08:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration