We help IT Professionals succeed at work.

Why can't I view contents of my home directory when logged in as root?

naseeam
naseeam used Ask the Experts™
on
I have Ubuntu 18.04 LTS (64-bit) laptop. Did I setup my root account properly?  When I login to my 'root' account, I cannot view contents of my home directory?  I cannot access /root directory?
su root
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

Commented:
one option is that /root does not exist.

ls -l / | grep -i root
su root does not reinitialize the login
su - root
should reinitialize the user's parameters and place the account at the root's home dir as defined in /etc/passwd
grep -i root /etc/passwd

Author

Commented:
listing_of_root
su dash root
grep_root
Distinguished Expert 2017

Commented:
The /root directory is empty.

Run ls -la to see the hidden files.

Author

Commented:
root_diectory_hidden_files
Distinguished Expert 2017

Commented:
Cd /root
ls -la

User directories do not have files within on install outside the hidden settings from /etc/skel
Commonly .bashrc, .profile .login in order to see them, you gave to use the -a option to ls.

Author

Commented:
root folder hidden files
Distinguished Expert 2017

Commented:
What are you expe ting to see?

The location is empty...

What where you expecting?
David FavorFractional CTO
Distinguished Expert 2018

Commented:
1) In all the above, I see no pwd command to show where you've logged in.

Use pwd to show your the exact directory.

2) You can find the dir Linux will use for your home directory by posting the output of...

grep ^root: /etc/passwd

Open in new window

3) Also to actually move into the root director at login, you must simulate a real login with su, as in...

su - root

Open in new window


Notice the "-" which simulates a login.

If you do a plain su, no "-" specified, then your environment + current working directory remain the same, reflecting values based on your initial login, not your su command.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Start by posting pwd before you su.

Then do a "su - root".

Then post pwd after your su command.

Author

Commented:
>> What are you expe ting to see?
I wrote simplest device driver (Hello World!), which includes some header files.  I was expecting to see header files in /root/include/linux directory.

move to root
Distinguished Expert 2017

Commented:
When did you do that, how did you do that..
If you su root you remained where you were before with fewer privileges.

Data dies not normally go into /root unless the driver was built but period to that was configured with --prefix=/root as an option

You may have run make install, but often the destination is /usr/local or /usr depending on the platform and package of the source......
Distinguished Expert 2017

Commented:
The other option
Make BASEDIR=/root install
Will redirect the install directives into /root the above option in some can be used to create a package...

Author

Commented:
>> When did you do that
Sorry I didn't write this driver yet.  I saw this driver in a book.  
I didn't write the driver yet because I didn't see any header files in my system that are included in this driver.
Distinguished Expert 2017
Commented:
default location for drivers are in /usr/include
any include or lib or sbin or bin folder in ~/ are local for the user.

there are system vendor which are commonly in /usr when one builds their own software or .. commonly the files are installed in /usr/local to distinguish them from the distribution (ldconfig and PATH commonly need to be adjusted to set the prefered search path to reflect ..

drivers are commonly not installed in a user space.


Commonly when compiling, building, it should be done by the unprivileged user to avoid an issue if the package was downloaded .. the unpribvileged user has minimal rights on the system.
only install to the system needs elevated rights to write into the /usr system space.
If you wrote your program in your own user account, it would be in ~amernaseem/ not in ~root.  You'd have to put it in root to have it show up in ~root.
Duncan RoeSoftware Developer

Commented:
To find out where your source files are, use locate. E.g.
locate helloworld.c

Open in new window

Author

Commented:
Thank you very much for great information and solutions.