• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • Life always offers you a second chance ... Its called tomorrow !!!

    Thursday, January 30, 2014

    What is the difference between "su" and "su -" ?

    If we check the man page for su
    su - run a shell with substitute user and group IDs

    which means that if you use
    # su -
    you are switching user to the root user and asking the system to change all the environment variables applicable to root and take me to the root's home directory

    Using su - is same as logging into a fresh session on a terminal

    For example
    [deepak@server ~]$ pwd

    [deepak@server ~]$ echo $PATH

    [deepak@server ~]$ sudo su -
    [root@server ~]# pwd

    [root@server deepak]# echo $PATH

    But when you type only su without a dash(-) in that case the session is switched to root(if any username is not mentioned along with su command) without applying any of the environment variable of the root user.

    Also the new user stays in the same directory as he was before using su
    [deepak@server ~]$ echo $PATH

    [deepak@server ~]$ pwd

    [deepak@server ~]$ sudo su
    [root@server deepak]# pwd

    [root@server deepak]# echo $PATH

    I hope I made my self clear.

    Follow the below links for more tutorials:

    What is a Kernel in Linux?
    How does a DNS query works when you type a URL on your browser?
    How to create password less ssh connection for multiple non-root users
    How to create user without useradd command in Linux
    How to unlink/delete a symbolic in Linux
    How to give normal user root privileges using sudo in Linux/Unix
    How to do Ethernet/NIC bonding/teaming in Red Hat Linux
    How to install/uninstall/upgrade rpm package with/without dependencies
    How to extract files to different directory using tar in Unix/Linux
    How to preserve Symbolic links with tar command in Unix/Linux
    How to give permission to user to run some commands in Linux
    How to set environment (PATH) variable permanently in Linux
    How to mount windows share on linux


    Post a Comment