Wednesday 22 June 2016

vipw -s & vigr -s Command use in Linux & Ubuntu for editing /etc/passwd, shadow, and group files / The best way to edit /etc/passwd, shadow, and group files.



The best way to edit /etc/passwd, or shadow or group file is to use vipw command. Traditionally (under UNIX and Linux) if you use vi to edit /etc/passwd file and same time a user try to change a password while root editing file, then the user’s change will not entered into file. To avoid this problem and to put a lock while editing file, use vipw and vigr command which will edit the files /etc/passwd and /etc/group respectively. If you pass -s option to these command, then they will edit the shadow versions of those files i.e. /etc/shadow and /etc/gshadow, respectively.

The main purpose of locks is to prevent file corruption. Do not use vi or other text editor to edit password file. Syntax:

  • vipw -s : Edit /etc/passwd file
  • vigr -s : Edit /etc/group file
Where,
  • -s : Secure file editing
An example :-

Login as a root user:


 [root@linuxbiginner ~]# vipw -s 


On other terminal login as normal user (for example anurag) and issue command passwd to change anurag’s password:

[anurag@linuxbiginner ~]# passwd
Changing password for user anurag.
Changing password for anurag.
(current) UNIX password:
New password:
Retype new password:
passwd: authentication tokens lock busy.

As you see it returned with an error “passwd: Authentication token lock busy”

This will avoid /etc/shadow file corruption.

Wednesday 15 June 2016

Linux and Unix pwd (Print Working Directory) command


 What is pwd?

pwd‘ stands for ‘Print Working Directory‘. As the name states, command ‘pwd‘ prints the current working directory or simply the directory user is, at present. It prints the current directory name with the complete path starting from root (/). This command is built in shell command and is available on most of the shell – bash, Bourne shell, ksh,zsh, etc.pwd is one of the simplest yet most popular and most widely used command. A good command over pwd is basic to use Linux terminal.

Basic syntax of pwd:

 pwd [OPTION]...

Options used with pwd
-L --logical         If the contents of the environment variable PWD provide an absolute name of the 
                     current directory with no "." or ".." components, then output those contents, 
                     even if they contain symbolic links. Otherwise, fall back to default -P handling.


-P --physical        Print a fully resolved name for the current directory, in which all components of
                     the name are actual directory names, and not symbolic links).

--help               Display a help message, and exit.

--version            Display version information, and exit.

This article aims at providing you a deep insight of Linux command ‘pwd‘.

1. Print your current working directory.

anurag@linuxgosolution:~$ /bin/pwd

/home/anurag

2. Print version of your ‘pwd’ command.

anurag@linuxgosolution:~$ /bin/pwd --version

pwd (GNU coreutils) 8.24
Packaged by Cygwin (8.24-3)
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jim Meyering.

Important: You might have noticed that we are executing the above command as “/bin/pwd” and not “pwd”.


3.
What is the absolute path (starting from /) of the pwd binary file.

/bin/pwd

4. What is the absolute path (starting from /) of the pwd source file.

/usr/include/pwd.h 


Tuesday 14 June 2016

Changing The Time Zone In Linux (Command Line)

There are several different ways to manage time in Linux. This quick tip will show you how to quickly change the local time to the correct time zone for the server. In this Linux tip I’ll show you how to change the localtime to your (or a) current time zone.
Location of the local time file
Linux looks at /etc/localtime to determine the current time of your machine. This can either be a symbolic link to the correct time zone or a direct copy of the time zone file.


Timezone files are located in /usr/share/zoneinfo/
For this tip we will assume your server is located in Asia and will be under the Kolkata  zone.
I change the Linux time zone by copying or making a symbolic link to from /usr/share/zoneinfo/Asia/Kolkata to /etc/localtime
For RHEL 6
1) cp /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
2) ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
For RHEL 7 & Ubuntu 14.04
1) timedatectl set-timezone Asia/Kolkata
Arun