See also switching users using su
Announcement
You can find all my latest posts on medium.Whenever a new user is created, by default, a set of (usually hidden) config files will get copied to the user’s new home folder. These files are actually duplicate of all the files contained in the /etc/skel
directory:
$ ls -la /etc/skel/ total 24 drwxr-xr-x. 2 root root 62 Feb 2 13:31 . drwxr-xr-x. 78 root root 8192 Mar 28 14:09 .. -rw-r--r--. 1 root root 18 Sep 6 2017 .bash_logout -rw-r--r--. 1 root root 193 Sep 6 2017 .bash_profile -rw-r--r--. 1 root root 231 Sep 6 2017 .bashrc
the useradd
commands automatically copies all the content from this folder and places it in the user’s home directory.
when a user logs into a RHEL machine (using username and password), the following scripts are executed automatically (in this order):
/etc/profile # (this sets up user env variables, e.g. path, hostname, histsize….etc)…this script will also trigger:
/etc/profile.d # (directory containing lots of other files.
{user’s home folder}/.bash_profile # can be used to add your own stuff including overriding what was set in the /etc/profile script.
{user’s home folder}/.bashrc # (used for setting local variables e.g. the PS1 variables)
However these does get executed when a non-login shell (aka interactive shell) is generated. a interactive shell is a shell that gets opened but without getting a username/password prompt. Here are some ways to start a non-login shell:
– Applications=>system tools=>terminal
– When you start a shell script, linux will automatically create a new shell for that script to run in, and this new shell is a non-login shell.
– At the command line, type ksh, followed by bash.
In a non-login shell the following scripts are run:
1. {user’s home folder}/bashrc,
2. /etc/bashrc,
3. /etc/profile.d (have a look through these script to familiarize yourself)
[post-content post_name=rhsca-quiz]
$ su – david # note: option l is implicitedly assumed here.
# or
$ su -l david
# or
$ ssh david@centos7machine
– /etc/profile # which in turn calls all scripts inside /etc/profile.d folder, and then it calls:
– ~/.bash_profile # (If for any reason this doesn’t exist, then it will look for ~/.profile) which in turn calls:
– ~/.bashrc # which in turn calls:
– /etc/bashrc
$ su david
# or:
$ bash
– ~/.bashrc # which in turn calls:
– /etc/bashrc
Note: all the profile related scripts are ignored. Hence privilege is set but environment variable are unset.
$ yum info nmap
$ yum install nmap
$ yum list all
$ yum list installed
$ yum list available
$ yum update
$ yum –enablerepo=epel install tree
$ yum grouplist
$ yum localinstall tree.rpm