Tuesday, January 28, 2020

CentOS / RHEL 7,8 : unable to start vsftpd service



While starting or restarting the vsftpd service you might get below error on an RHEL 7 system.


# systemctl restart vsftpd.service 
 
Job for vsftpd.service failed. See 'systemctl status vsftpd.service' and 'journalctl -xn' for details.
If it is the first time you are starting vsftpd you might have to update few parameters in the configuration file /etc/vsftpd/vsftpd.conf for it to work. Follow the steps below to get the vsftpd service working.

1. Update below parameters in /etc/vsftpd/vsftpd.conf file. By default the parameter listen has a value “NO” assigned to it and parameter listen_ipv6 is uncommented.

listen=YES              # default is NO
#listen_ipv6=YES  # default is uncommented

2. Restart vsftpd service once you have made the above changes.

# systemctl restart vsftpd.service

3. Make sure there no syntax error in the vsftpd configuration file – etc/vsftpd/vsftpd.conf. Run the vsftpd command and verify the functionality.

# vsftpd

Wednesday, January 8, 2020

Extending CentOS 7 File System after Resizing the Volume ( Root without Reboot) - LVM

increase disk size of the VM (VMware AWS and Azure provide visual interface to do this task)

scan the disk to see the new disk size, run the following command for the kernel to learn the new disk size

echo 1 > /sys/block/sda/device/rescan

then install the cloud-utils-growpart script:

yum install cloud-utils-growpart
Next, use it to grow the logical partition to extend to all the available space:
growpart /dev/sda 2
pvresize /dev/sda2
Extend and Resize filesystem
lvextend -l+100%FREE -r /dev/centos/root

Thursday, September 12, 2019

Interrupt the boot process in order to gain access to a system- root password recovery



Note: This is a critical RHCSA 7 exam objective (if you can’t take control of a VM through a reboot at the beginning of the exam, you will fail it entirely).

Presentation

In RHEL 7, the procedure to get access to a system during the boot process and modify the root password has changed because of the adoption of Systemd.
There were several procedures floating around to recover the root password. Some were working with physical servers but not with virtual machines, some the other way around.
The following procedure works all the time.
Procedure

At the beginning of the boot process, at the GRUB 2 menu, type the e key to edit.
Then, go to the kernel line (the line starting with linux16) and add the following statements at the end:
rd.break enforcing=0

Caution: The keys to press are those of a US keyboard (querty).
Note: rd.break asks for a break at an early stage of the boot process. enforcing=0 puts the system into SELinux Permissive mode. Don’t confuse with selinux=0 that completely disables SELinux.
Press Ctrl x to resume the boot process.

Then, mount the /sysroot partition as read/write:
switch_root:/# mount –o remount,rw /sysroot

Execute the chroot command on the /sysroot partition:
switch_root:/# chroot /sysroot

Change the root password:
sh-4.2# passwd root
Changing password for user root.
New passwd: mypassword
Retype new password: mypassword
passwd: all authentication token updated successfully.
sh-4.2# exit
exit
switch_root:/# exit
logout

Connect to your server at the console (don’t reboot now!) with the root user and the new password:
...
[  OK  ] Started Network Manager Script Dispatcher Service.
[  OK  ] Started Crash recovery kernel arming.
[  OK  ] Reached target Multi-User System.
 
CentOS Linux 7 (Core)
Kernel 3.10.0-229.14.1.el7.x86_64 on an x86_64
 
vm login: root
Password: mypassword

Thursday, August 1, 2019

Recreating an XFS file system with `ftype=1` Centos 7 (docker overlay2 storage dirver requirement)

Recreating an XFS file system with `ftype=1` CentOS 7


The CentOS 7 system where the root file system is XFS (created with ftype=0the default CentOS)
setting at the time the system was installed). Unfortunately, the Docker overlay2 storage driver 
requires that file system to have been created with ftype=1:

proposed method seemed to work fine. Here's the procedure:
  1. Boot into CentOS-7-x86_64-LiveGNOME-1804.iso.
  2. Open a terminal and sudo -s.
  3. Scan for LVM volumes: vgscan
  4. Change into the appropriate volume group (centos in my case): vgchange -ay centos
  5. Scan for the logical volumes in that group: lvscan
  6. Create a mount point for the root FS: mkdir /mnt/root
  7. Mount the logical volume corresponding to the root FS: mount /dev/centos/root /mnt/root
  8. Dump to remote host: xfsdump -J - /mnt/root | 'cat >/data/rootfs.dump'
  9. Unmount the root FS: umount /mnt/root
  10. Recreate the root FS: mkfs.xfs -f -n ftype=1 /dev/centos/root
  11. Mount the recreated root FS: mount /dev/centos/root /mnt/root
  12. Restore from remote host: 'cat /data/rootfs.dump' | xfsrestore -J - /mnt/root
  13. Reboot. Everything should be as it was before, except xfs_info / should now show ftype=1

Wednesday, November 7, 2018

chmod - permissions - linux

PermissionCommand ExamplesDescription
rwx rwx rwxchmod 777 filename
chmod -R 777 dir
Anybody can read, write, execute.
rwx rwx r-xchmod 775 filename
chmod -R 775 dir
Owner & Group can read, write, execute. Everyone else can read, execute.
rwx rwx r–chmod 774 filename
chmod -R 774 dir
Owner & Group can read, write, execute. Everyone else can read.
rwx r-x r-xchmod 755 filename
chmod -R 755 dir
Owner can read, write, execute. Everyone else can read, execute.
rwx — —chmod 700 filename
chmod -R 700 dir
Owner can read, write, execute. No one else has any rights.
rw- rw- rw-chmod 666 filename
chmod -R 666 dir
Everyone can read, write.
rw- rw- r–chmod 664 filename
chmod -R 664 dir
Owner & Group can read, write. Everyone else can read.
rw- r– r–chmod 644 filename
chmod -R 644 dir
Owner can read, write. Everyone else can read.

Friday, August 26, 2016

Data Migration/Copy/Backup Using rsync command in Linux

rsync - stands for remote sync

rsync is used to perform the backup operation/data Migration in UNIX / Linux.
rsync utility is used to synchronize the files and directories from one location to another in an effective way. Backup location could be on local server or on remote server

Syntax

$ rsync options source destination
Source and destination could be either local or remote. In case of remote, specify the login name, remote server name and location.
options:
  • -z is to enable compression
  • -a = archive ( it preserves permissions (owners, groups), times, symbolic links, and devices  =  -rlptgoD)
  • -v verbose     ( it shows on the screen what is being copied )
  • -r indicates recursive ( it copies directories and sub directories)
  • -e rsync will use ssh
Examples:

Synchronize Two Directories in a Local Server

$ rsync -zvr /tmp/source_dir/ /destination_dir

Preserve timestamps during Sync using rsync -a

$ rsync -azv /tmp/source_dir/ /destination_dir/

Synchronize Files From Local to Remote

rsync -avz /tmp/source_dir/ user@192.168.1.1:/tmp/destination_dir/
Password:

Synchronize Files From Remote to Local

rsync -avz user@192.168.1.1:/tmp/remote_source_dir/ /tmp/local_destination_dir/
Password:

rsync using ssh

rsync -avz -e ssh user@192.168.1.1:/tmp/remote_source_dir/ /tmp/local_destination_dir/
Password:

View the Progress during rsync Transfer

rsync -avz --progress user@192.168.1.1:/tmp/remote_source_dir/ /tmp/local_dest_dir/
Password:

Specify --max-size of file for rsync Transfer (>100K will not be transfer)

rsync -avz --max-size='100K' user@192.168.1.1:/tmp/remote_srce_dir/ /tmp/local_dest_dir/
Password:

Transfer the Whole File with rsync -W

normally rsync transfers only the changed block to the destination, instead of sending the whole file, with the option -W it transfer the whole file

rsync -avzW user@192.168.1.1:/tmp/remote_srce_dir/ /tmp/local_dest_dir/
Password:

Wednesday, July 13, 2016

Mount NTFS Partition in RHEL/CentOS


Enable NTFS support on CentOS Linux version 5 or 6? 
Mount ntfs partition under RHEL 5 or 6?

First need to install EPEL repo on RHEL / CentOS version 6.x

# cd /tmp
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm


# yum install epel-release-6-5.noarch.rpm

NTFS-3G
NTFS-3G is a stable, open source, GPL licensed, POSIX, read/write NTFS driver for Linux.
It provides safe handling of the Windows XP, Windows Server 2003, Windows 2000, Windows Vista, Windows Server 2008 and Windows 7 NTFS file systems.
NTFS-3G can create, remove, rename, move files, directories, hard links, and streams.
it can read and write normal and transparently compressed files, including streams and sparse files.
it can handle special files like symbolic links, devices, and FIFOs, ACL, extended attributes.
moreover it provides full file access right and ownership support.

Install NTFS-3G 


# yum install ntfs-3g


Find Out NTFS Partition Name


# fdisk -l /dev/sda
# fdisk -l /dev/sdb

How to Mount /dev/sda1 NTFS Partition at /mnt/ntfs


load the fuse driver
# modprobe fuse

Create a mount point
# modprobe fuse

mount the ntfs partition, enter:
# mount -t ntfs-3g /dev/sda1 /mnt/ntfs

You can use regular Unix commands to copy or access the files:
df -h
 mount
 cd /mnt/ntfs
cp test /tmp

Unmount NTFS Partition


# umount /mnt/ntfs