How to Reset Forgotten Root Password on Linux RHEL 7/CentOS 7

Reset Forgotten Root Password

This article will explain the steps to reset a lost root password or to reset forgotten root password on Linux RHEL 7 or CentOS 7.

Basically, the steps will adding a “rd.break” to the end of the line with kernel parameters in Grub to stops the start up process before the regular root filesystem is mounted, hence the necessity to chroot into sysroot. Continue reading “How to Reset Forgotten Root Password on Linux RHEL 7/CentOS 7”

Rescan SCSI Bus to Add or Remove a SCSI Devices on Linux

Rescan SCSI bus

When you need to add a hard disk or network interface cards on the new VMware virtual machine on the production server, but you are not allowed to shutdown the server or you have several related issues as below. The following quick article shows how to rescan SCSI Bus to add or remove a SCSI Devices on Linux.

This steps may work on CentOS 5/6/7 and RHEL 5/6/7.

Other related Issues

  • Is it possible to add or remove a SCSI device without rebooting a running system?
  • Can you scan a SCSI bus for new or missing SCSI devices without rebooting?
  • How can I make newly connected SCSI storage devices available without rebooting?
  • What is the Linux equivalent to the Solaris command devfsadm to add or remove storage devices?
  • I am trying to add a LUN to a live system but it is not recognized
  • I am trying to add a tape drive to a live system but it is not recognized
  • I am trying to add a disk drive to a live system but it is not recognized
  • How can I force a rescan of my SAN to find newly associated LUNs?
  • What to do if a newly allocated LUN on my SAN is not available?
  • Unable to probe for a newly allocated LUN
  • Some nodes can’t see my new storage device, how can I make it available?
  • After SAN maintenance activity, not all devices returned – devices in multipath missing or remain in failed state.
  • After SAN failover testing completed, not all devices returned to running state as expected – devices in multipath missing or remain in failed state.
  • What is the best way to remove a SCSI disk from the system

After Red Hat Enterprise Linux 5.0 (RHEL 5) and above (RHEL 6 and RHEL 7), it is possible to make changes to the SCSI I/O subsystem without rebooting.

How to Rescan SCSI Bus to Add or Remove a SCSI Devices on Linux

1. Identify host bus number :

# ls /sys/class/scsi_host/
host0  host1  host2

2. Rescan the SCSI Bus to Add a SCSI Devices :

# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
# echo "- - -" > /sys/class/scsi_host/host2/scan

Reference :

How to Setup VsFTPD Service with SSL/TLS on Linux CentOS 7 / RHEL 7 / Oracle Linux 7

Setup VsFTPD service

If you have your own dedicated server or virtual private server (VPS) that run in linux operating system to host your website or blog, it is recommended to install and setup ftp Service in order to facilitate the transfer of files and update your website. Among the well-known FTP software is VsFTPD.

VsFTPD means “Very Secure FTP Daemon” is the free FTP for Linux and UNIX operating systems, which are very stable, fast and safe to use even if the server is in the internet.

Is ftp secure ?

Any server in the internet is vulnerable to intruders that may spying on data transfer and steal confidential information such as id and password if encryption is not configured.

In this article, I will share the basic steps to setup VsFTPD service with SSL/TLS encryption on CentOS 7, RHEL 7 and Oracle Linux 7 operating system.

Steps to Setup VsFTPD Service with SSL/TLS

1. Install and setup VsFTPD Service :

# yum install vsftpd -y

2. Add ftp user :

# useradd user1
# passwd user1
Changing password for user user1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

3. Now Edit VsFTPd configuration file /etc/vsftpd/vsftpd.conf :

Enable the following :

..
..
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
..
..

Optionaly. you can customize the banner :

..
..
# You may fully customise the login banner string:
ftpd_banner=Welcome to ehowstuff FTP service.
..
..

4. Create ssl and private directory :

# mkdir -p /etc/vsftpd/ssl
# mkdir -p /etc/vsftpd/ssl/private/

5. Create a SSL certificate using on of following command :

# openssl req -x509 -nodes -days 720 -newkey rsa:2048 -keyout /etc/vsftpd/ssl/private/vsftpd.key -out /etc/vsftpd/ssl/vsftpd.pem

You will be prompted with a series of question, which you answer as they appear :

Example :

# openssl req -x509 -nodes -days 720 -newkey rsa:2048 -keyout /etc/vsftpd/ssl/private/vsftpd.key -out /etc/vsftpd/ssl/vsftpd.pem
Generating a 2048 bit RSA private key
......................+++
..........................+++
writing new private key to '/etc/vsftpd/ssl/private/vsftpd.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:MY
State or Province Name (full name) []:Malaysia
Locality Name (eg, city) [Default City]:Kuala Lumpur
Organization Name (eg, company) [Default Company Ltd]:ehowstuff
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:centos7
Email Address []:admin@ehowstuff.local

6. Assign the permission :

# chmod 400 /etc/vsftpd/ssl/vsftpd.pem
# chmod 400 /etc/vsftpd/ssl/private/vsftpd.key

7. Edit vsftpd configuration file /etc/vsftpd/vsftpd.conf. Specify the location of our certificate and key files then add the following line at the bottom of vsftpd.conf :

..
..
# Add follows to the bottom
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES

ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
rsa_cert_file=/etc/vsftpd/ssl/vsftpd.pem
rsa_private_key_file=/etc/vsftpd/ssl/private/vsftpd.key

8. Stop and Start VsFTPD Service and make it auto start at boot :

# systemctl stop vsftpd
# systemctl start vsftpd
# systemctl enable vsftpd

9. Check VsFTPD status :

# systemctl status vsftpd
vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled)
   Active: active (running) since Sat 2014-12-13 10:31:30 MYT; 34s ago
  Process: 20864 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 20865 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           ââ20865 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Dec 13 10:31:30 centos7.ehowstuff.local systemd[1]: Starting Vsftpd ftp daemon...
Dec 13 10:31:30 centos7.ehowstuff.local systemd[1]: Started Vsftpd ftp daemon.

10. From client PC, open filezilla and connect to your server and enter info, for encryption field, select “explicit FTP over TLS”.
vsftpd-centos7-1

Click the check box “Always trust certificate in the future sessions.” Then clik OK to proceed.
vsftpd-centos7-2

I hope this article gives you some ideas and essential guidance on how to setup VsFTPD service with SSL/TLS encryption on CentOS 7, RHEL 7 and Oracle Linux 7 operating system.

Resources :

3 Command to Change the Linux Date and Time in CentOS 7/RHEL 7

Red Hat Enterprise Linux 7 or CentOS 7 come with three default utilities or command line that help to configure and display the information about the system date and time:

3 Command to Change the Linux Date and Time in CentOS 7/RHEL 7

1.The timedatectl utility, which is new in Red Hat Enterprise Linux 7 and is part of systemd;
2.The traditional date command;
3.The hwclock utility for accessing the hardware clock.

1. timedatectl Utility

The timedatectl utility is a part of the systemd system and service manager that allows you to change the current date and time of the linux system.

1.1. How to check time server linux using timedatectl ?

Run the timedatectl command with no additional command line options:

[root@centos7 ~]# timedatectl
      Local time: Mon 2014-11-03 22:44:24 MYT
  Universal time: Mon 2014-11-03 14:44:24 UTC
        RTC time: Mon 2014-11-03 14:44:24
        Timezone: Asia/Kuala_Lumpur (MYT, +0800)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

1.2. How to set date on centos sing timedatectl ?

timedatectl set-time YYYY-MM-DD

Example of change the current date :

[root@centos7 ~]# timedatectl set-time 2014-11-04

1.3. How to change server time centos using timedatectl ?

timedatectl set-time HH:MM:SS

Example of change the current time :

[root@centos7 ~]# timedatectl set-time 00:50:00

1.4. How to change the Time Zone using timedatectl ?

Use the following command to list all available time zones in Asia :

[root@centos7 ~]# timedatectl list-timezones | grep Asia
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Baghdad
..
Asia/Kuala_Lumpur
..

In order to change the time zone to Asia/Kuala_Lumpur, type the following command as a root user :

[root@centos7 ~]# timedatectl set-timezone Asia/Kuala_Lumpur

2. date Utility

The date utility is available on all Linux systems. date allows you to display and change the current date and time and it is frequently used in scripts to display the system clock.

2.1. How to display the current Date and Time using date ?

To display the current date and time, run the date command with no additional command line options:

[root@centos7 ~]# date
Tue Nov  4 01:12:39 MYT 2014

This displays the day of the week followed by the current date, local time, abbreviated time zone, and year.

2.2. How to display the current Date and Time in customized the format ?

You can also customize the format of the displayed information by providing the +”format” option on the command line:

date +"format"

Example :

[root@centos7 ~]# date +"%Y-%m-%d %H:%M"
2014-11-04 01:20

2.3. How to change the current time using date ?

In order to change the current date and time, type the date command with the –set or -s option as a root user :

To change the current time, run the date command with the –set or -s option as root:

date +%T -s HH:MM:SS

Replace HH with an hour, MM with a minute, and SS with a second, all typed in a two-digit form.

As an example change the current time to 11:56 p.m., as a root, run the following command :

[root@centos7 ~]# date +%T --set 23:56:00

3. hwclock Utility

hwclock is a utility for accessing the hardware clock. Hardware clock is independent of the operation system you use and works even when the machine is shut down. This program is used to find out the time from the hardware clock and set the system time at boot time.

3.1 How to display the Current Date and Time using hwclock ?

To display the current date and time, run hwclock with no command line options as a root :

[root@centos7 ~]# hwclock
Tue 04 Nov 2014 01:41:08 AM MYT  -0.131049 seconds

3.2. How to change the current Date and Time using hwclock ?

In order to change the hardware clock date and time, you can do so by appending –set and –date options along with your specification:

hwclock --set --date "dd mmm yyyy HH:MM"

As an example, if we want to set the date and time to to “15:20, October 29, 2015”, run the command in the following format:

[root@centos7 ~]# hwclock --set --date "29 Oct 2015 15:20"

Note : In Red Hat Enterprise Linux 6 / CentOS 6, the hwclock command was run automatically on every system shutdown or reboot, but it is not in Red Hat Enterprise Linux 7 /CentOS 7.

For more information on how to change the Linux Date and time in Red Hat Enterprise Linux 7 and CentOS 7, please read the manual page for the timedatectl, date and hwclock.

How to Change Date and Time Linux on RHEL 6/7 and CentOS 6/7

Change Date and Time

This post assumed that your Red Hat Enterprise Linux 6 (RHEL 6) does not have Date/Time Properties installed. In order to change the date and

In order to change date and time you will have to perform the changes from the command line. Note that in order to perform actions described in this post, you have to be logged in as a root:

1. Change the current date with the following form :

# date +%D -s YYYY-MM-DD

Linux Date Format : YYYY with a four-digit year, MM with a two-digit month, and DD with a two-digit day of the month.
Example :

# date +%D -s 2012-05-30
05/30/12

2. Change the current time with the following form :

# date +%T -s HH:MM:SS

If your system clock is set to use UTC (Coordinated Universal Time), add the following option :

# date +%T -s HH:MM:SS -u

Note : HH stands for an hour, MM is a minute, and SS is a second

Example :

# date +%T -s 22:30:00
22:30:00

or

[root@rhel6 ~]# date +%T -s 22:30:00 -u
22:30:00

3. How to Display current date and time :

[root@rhel6 ~]# date
Wed May 30 22:30:04 MYT 2012

Reference

How to Change Timezone Linux on RHEL 6/7 and CentOS 6/7

change timezone linux

This post assumed that we will change the System Timezone from the command line without using redhat-config-date.

There are several files and directories that are used for time zones. In RHEL 6 and RHEL 6, there is one directory that very useful to select the appropriate time zone which is /usr/share/zoneinfo directory.

Sometimes we forget to set the correct time zone for the new linux system. This quick steps show how to change timezone on RHEL 6/7 and CentOS 6/7.

/usr/share/zoneinfo – this directory contains the System Timezone files that were compiled by zic. These are binary files and cannot be viewed with a text viewer. The files contain information such as rules about DST. They allow the kernel to convert UTC UNIX time into appropriate local dates and times.

In order to change the System Timezone of your system you will need to access the file or configuration using root.

How to Change Timezone Linux on RHEL / CentOS

1) How to list all available time zone on RHEL 6 / CentOS 6:

#ls /usr/share/zoneinfo

2) How to list all available time zone on RHEL 7 / CentOS 7:

# timedatectl list-timezones | grep Asia
Asia/Aden
Asia/Almaty
Asia/Amman
..
..
Asia/Kuala_Lumpur

3) How to check timezone in linux RHEL 6 / CentOS 6 :

# cat /etc/sysconfig/clock

4) How to check timezone in linux RHEL 7 / CentOS 7 :

# timedatectl status
      Local time: Thu 2017-01-05 20:00:22 MYT
  Universal time: Thu 2017-01-05 12:00:22 UTC
        RTC time: n/a
       Time zone: Asia/Kuala_Lumpur (MYT, +0800)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

5) How to Change Timezone Linux RHEL 6 / CentOS 6 :

Edit ZONE= to the following:

# cat /etc/sysconfig/clock
ZONE="Asia/Kuala_Lumpur"

Create a new soft link to your time zone :

# mv /etc/localtime /root/localtime.old
# ln -sf /usr/share/zoneinfo/Asia/Kuala_Lumpur /etc/localtime

6) How to Change Timezone Linux RHEL 7 / CentOS 7 :

timedatectl set-timezone Asia/Kuala_Lumpur

7) How to Display current date and time and timezone :

# date
Thu Jan  5 19:54:38 MYT 2017

Reference :

How to Install Unzip to Extract Zip File on Linux RHEL, CentOS, Oracle Linux 6/7

Question :
When i try to extract .zip file, i get the following error :

# zip
-bash: zip: command not found
# unzip
-bash: unzip: command not found

As example, i try to extract “Joomla_2.5.4-Stable-Full_Package.zip” file, but it return me this error :

# unzip Joomla_2.5.4-Stable-Full_Package.zip
-bash: unzip: command not found

Solution :

Unzip will list, test, or extract files from a ZIP archive. Above error shown that the unzip utility was not installed on linux server by default. You have to install it manually. In order to Unzip to Extract Zip File on Linux RHEL 6/7, CentOS 6/7 and Oracle Linux 6/7, you have to install the unzip or zip utility, run the following command :

# yum install zip unzip -y

See zip utility command usage and option :

# zip
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  The default action is to add or replace zipfile entries from list, which
  can include the special name - to compress standard input.
  If zipfile and list are omitted, zip compresses stdin to stdout.
  -f   freshen: only changed files  -u   update: only changed or new files
  -d   delete entries in zipfile    -m   move into zipfile (delete OS files)
  -r   recurse into directories     -j   junk (don't record) directory names
  -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
  -1   compress faster              -9   compress better
  -q   quiet operation              -v   verbose operation/print version info
  -c   add one-line comments        -z   add zipfile comment
  -@   read names from stdin        -o   make zipfile as old as latest entry
  -x   exclude the following names  -i   include only the following names
  -F   fix zipfile (-FF try harder) -D   do not add directory entries
  -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
  -T   test zipfile integrity       -X   eXclude eXtra file attributes
  -y   store symbolic links as the link instead of the referenced file
  -e   encrypt                      -n   don't compress these suffixes

See unzip utility command usage and option :

# unzip
UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

Unzip Linux Example

How to extract tgz file in linux ?

# tar xvzf filename.tar.gz

x: To extract the files.

v: List all of the files one by one in the archive. Produce verbose output.

z: The z option is very important and tells the tar command to uncompress the file (gzip).

f: Read the archive from the archive to the specified file. In this example, read filename.tar.gz archive.

How to extract zip file in linux ?

Extract zip file filename.zip :

# unzip filename.zip

Extract to alternate destination :

# unzip filename.zip -d /data

How to Compress and zip file and folder in Linux ?

# tar -czvf filename.tar.gz /path/directory

How to extract all gz in a directory in Linux ?

# gunzip *.gz

How to decompress files Using The “gzip” in Linux ?

# gzip -d filename.gz

How to decompress A File Using The “gunzip” n Linux ?

# gunzip filename.gz

How to Check Server Uptime in Linux

Server UptimeInformation about how long the system has been running or server uptime is not critical for some people. But it is important for server administrators. Servers that run mission-critical applications must run as long as possible. Sometimes it must be zero downtime. Information about the uptime is very useful in many cases it helps to audit how long the server is running.

In this tutorial, we will learn about the command to find the system uptime in linux.Uptime system uptime means how long the server has been running since the last shutdown or reboot.

Question :
How to check unix or linux server uptime ? What command Should i run ?

Answer :
1. Run uptime command :

# uptime

Sample outputs:

 22:54:34 up  1:26,  1 user,  load average: 0.11, 0.03, 0.01

The uptime command gives a one line display of the following information.

  • The current time (22:54:34)
  • How long the system has been running (up 1 hour 26 Minutes)
  • How many users are currently logged on (1 user)
  • The system load averages for the past 1, 5, and 15 minutes (0.11, 0.03, 0.01)

2. You can use w command to check server uptime

# w

Sample outputs:

 23:06:57 up  1:38,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.1.52     21:30    0.00s  1.85s  0.01s w

Please note that the w command also displays who is logged together with uptime info above.

3. Check server uptime using top command.

# top
top - 23:27:01 up 4 days, 10:20,  1 user,  load average: 0.22, 0.12, 0.09
Tasks: 163 total,   1 running, 162 sleeping,   0 stopped,   0 zombie
%Cpu(s):  6.1 us,  1.0 sy,  0.0 ni, 92.7 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  4043436 total,   282644 free,  1044916 used,  2715876 buff/cache
KiB Swap:  8388600 total,  8316440 free,    72160 used.  2905352 avail Mem