centos7 – My Random Tips https://www.myrandomtips.com Useful Tips to Save Time Wed, 10 Sep 2025 01:26:38 +0000 en hourly 1 https://wordpress.org/?v=6.8.2 https://www.myrandomtips.com/wp-content/uploads/2017/10/cropped-light-bulb-icon-42x42.png centos7 – My Random Tips https://www.myrandomtips.com 32 32 linux directory size https://www.myrandomtips.com/linux/linux-directory-size/ https://www.myrandomtips.com/linux/linux-directory-size/#respond Sun, 25 Aug 2019 13:47:20 +0000 https://www.myrandomtips.com/?p=765 This guide will teach you several commands I use frequently on how to show the linux directory size in Centos or Redhat and what folders are using the most space all listed in MB. Here is a list of common commands I use that you may find helpful. Search current Centos or RedHat Folder You… Read More »

The post linux directory size appeared first on My Random Tips.

]]>
linux directory size 1174x665

This guide will teach you several commands I use frequently on how to show the linux directory size in Centos or Redhat and what folders are using the most space all listed in MB.

Here is a list of common commands I use that you may find helpful.

Search current Centos or RedHat Folder

You search the current folder sizes down in the command using this command:

du -h –max-depth=1  |grep -v -e [0-9].[0-9]K -e [0-9][0-9]K -e ^0 | sort -n

foldersie

Find top 10 largest files in a folder in linux

You search a given folder for the largest top 10 files in a given folder using this command:

find /home/simon/Downloads -xdev -type f -exec du -sk {} \; |sort -rn | head -10

top10filesize

Show drive using high percentage in linux

You can you do a quick search to find which drives are using a higher percentage of used space, can be useful if running a script over ssh keys just change the number on what threshold to show using this command:

df -P | awk ‘0+$5 >= 70 {print}’

drivepercentage
Example of changing the limit to 10%

Install a package to check linux directory size

Ncdu is an acronym of NCurses Disk Usage. It is a fast way to see what directories are using the disk space. It is simple and fast disk usage analyzer which is used to find which directories or files are taking up more space.

To install on RHEL, CentOS

yum install ncdu

ncdu install

Once installed, just type ncdu to get going:

ncdu output

ncdu Keyboard Shortcuts

up, down j, k – Cycle through the items
right, enter, l – Open selected directory
left, <, h – Go to parent directory
n – Order by filename (press again for descending order)
s – Order by filesize (press again for descending order)
C – Order by number of items (press again for descending order)
a – Toggle between showing disk usage and showing apparent size.
M – Order by latest child mtime, or modified time. (press again for descending order) Requires the -e flag.
d – Delete the selected file or directory. An error message will be shown when the contents of the directory do not match or do not exist anymore on the filesystem.
g – Toggle between showing percentage, graph, both, or none. Percentage is relative to the size of the current directory, graph is relative to the largest item in the current directory.
c – Toggle display of child item counts.
m – Toggle display of latest child mtime, or modified time. Requires the -e flag.
e – Show/hide ‘hidden’ or ‘excluded’ files and directories. Please note that even though you can’t see the hidden files and directories, they are still there and they are still included in the directory sizes.
i – Show highlighted item info about the usage and size
r – Recalculate the current directory.
b – Spawn bash shell in current directory.
q – Quit ncdu.

NCDU Examples

To scan and browse the directory you’re currently in, all you need is a simple:

ncdu
If you want to scan a full filesystem, your root filesystem, for example, then you’ll want to use -x:

ncdu -x /

Since scanning a large directory may take a while, you can scan a directory and export the results for later viewing:

ncdu -1xo- / | gzip >export.gz

…some time later:

zcat export.gz | ncdu -f-
To export from a cron job, make sure to replace -1 with -0 to suppress any unnecessary output.

You can also export a directory and browse it once scanning is done:

ncdu -o- | tee export.file | ./ncdu -f-


The same is possible with gzip compression, but is a bit kludgey:

ncdu -o- | gzip | tee export.gz | gunzip | ./ncdu -f-

To scan a system remotely, but browse through the files locally:

ssh -C user@system ncdu -o- / | ./ncdu -f-

The -C option to ssh enables compression, which will be very useful over slow links. Remote scanning and local viewing has two major advantages when compared to running ncdu directly on the remote system: You can browse through the scanned directory on the local system without any network latency, and ncdu does not keep the entire directory structure in memory when exporting, so you won’t consume much memory on the remote system.

Summary

As you can see linux directory size can be determined with multiple different ways, if you have any that you use frequently please add into the comments below.

For other Linux / Unix related tutorials on my website please click here.

Also please have a look at my YouTube Channel and subscribe for video tutorials as they are released, and if you have any advice for others, requests or questions please leave a comment below.

The post linux directory size appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/linux-directory-size/feed/ 0
Linux ate my RAM Script to Check Usage https://www.myrandomtips.com/linux/linux-ate-my-ram/ https://www.myrandomtips.com/linux/linux-ate-my-ram/#respond Sun, 03 Mar 2019 11:39:25 +0000 https://www.myrandomtips.com/?p=665 Linux ate my ram is a worrying thing to look at the first time you check top or free -m as it appears the linux cached memory high and showing the buff/cache too high. Understanding how linux uses disk caching for the speed of your system, and how everything is ok, and how to check… Read More »

The post Linux ate my RAM Script to Check Usage appeared first on My Random Tips.

]]>

Linux ate my ram is a worrying thing to look at the first time you check top or free -m as it appears the linux cached memory high and showing the buff/cache too high.

Understanding how linux uses disk caching for the speed of your system, and how everything is ok, and how to check if there is an issue will help any newcomers to Linux.

(more…)

The post Linux ate my RAM Script to Check Usage appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/linux-ate-my-ram/feed/ 0
Increase swap space in Redhat 7 | Centos 7 https://www.myrandomtips.com/linux/increase-swap-space-redhat-7-centos-7/ https://www.myrandomtips.com/linux/increase-swap-space-redhat-7-centos-7/#respond Fri, 22 Feb 2019 16:44:18 +0000 https://www.myrandomtips.com/?p=578 So you would like to add more swap space in Redhat 7 or Centos 7 after installation. Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system from 512 MB to 1026 MB, but there is only 512 MB of swap space.… Read More »

The post Increase swap space in Redhat 7 | Centos 7 appeared first on My Random Tips.

]]>
So you would like to add more swap space in Redhat 7 or Centos 7 after installation.

Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system from 512 MB to 1026 MB, but there is only 512 MB of swap space. It might be advantageous to increase the amount of swap space to 1026 MB if you perform memory-intense operations or run applications that require a large amount of memory. It is recommended that you extend an existing logical volume.

How To increase swap space in Redhat 7 | Centos 7

How to Increase Swap Space in Redhat 7 or Centos 7

4 Step on extending the logical volume

  1. Check if enough space to extend the swap file
  2. Turn off the swap file
  3. Extend the swap file and format
  4. Turn back on the swap file and check if swap file has increased

Extend swap on an existing LVM2 logical volume

First make sure nothing is using the swap volume and also ensure you have enough space in your volume group.

Commands to Check enough Space

cat /etc/fstab # check name of swap volume group e.g /dev/mapper/centos-swap swap

lvdisplay /dev/mapper/centos-swap # show volume group info for VG Name

vgdisplay centos # show how much space is free in VG e.g. centos

How to Extend the Swap Volume

1. Disable swapping for the associated logical volume:

swapoff -v /dev/mapper/centos-swap

2. Resize the LVM2 logical volume by 256 MB:

lvm lvresize /dev/mapper/centos-swap -L +256M

3. Format the new swap space:

mkswap /dev/mapper/centos-swap

4. Enable the extended logical volume:

swapon -va

5. Test that the logical volume has been extended properly:

cat /proc/swaps free

Summary

I hope this guide is some help on how to add more swap space in Redhat 7 or Centos 7 after installation, it can be very useful when increasing the physical ram on your Redhat 7 or Centos 7 box.

For other Redhat related tutorials on my website please click here.

To Check our More Tips Please have a look at my YouTube Channel and subscribe for video tutorials as they are released, and if you have any requests please leave a comment below.

The post Increase swap space in Redhat 7 | Centos 7 appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/increase-swap-space-redhat-7-centos-7/feed/ 0
create ssh key https://www.myrandomtips.com/linux/create-ssh-key/ https://www.myrandomtips.com/linux/create-ssh-key/#respond Thu, 06 Sep 2018 06:46:34 +0000 https://www.myrandomtips.com/?p=472 In Linux and most other Linux distributions you can use ssh key pairs to easily remote into other systems and run scripts remotely. This is extremely useful when managing multiple Linux hosts and if you wish to gather reports from one central source. What are SSH Key Pairs? SSH key pairs are two cryptographically secure keys… Read More »

The post create ssh key appeared first on My Random Tips.

]]>
How to create ssh key pairs in Linux

In Linux and most other Linux distributions you can use ssh key pairs to easily remote into other systems and run scripts remotely. This is extremely useful when managing multiple Linux hosts and if you wish to gather reports from one central source.

What are SSH Key Pairs?

SSH key pairs are two cryptographically secure keys that can be used to authenticate a client to an SSH server. Each key pair consists of a public key and a private key.

The private key is retained by the client and should be kept absolutely secret. Any compromise of the private key will allow the attacker to log into servers that are configured with the associated public key without additional authentication. As an additional precaution, the key can be encrypted on disk with a passphrase.

The associated public key can be shared freely without any negative consequences. The public key can be used to encrypt messages that only the private key can decrypt. This property is employed as a way of authenticating using the key pair.

The public key is uploaded to a remote server that you want to be able to log into with SSH. The key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys.

When a client attempts to authenticate using SSH keys, the server can test the client on whether they are in possession of the private key. If the client can prove that it owns the private key, a shell session is spawned or the requested command is executed.

These 3-steps are how to create ssh key pairs in Linux:

  1. Create your ssh key pairs on the client server you wish to connect from.
  2. Copy your public key onto the host you wish to connect to.
  3. Load your ssh key on the client server your connecting from.

An overview of the flow is shown in this diagram:

sshkeyauth

The diagram shows a laptop connecting to a server, but it could just as easily be one server connecting to another server.

  • private key (id_rsa) – this is the master key that sits on your client your connecting from.
  • public key (id_rsa.pub) – like a door lock sits on the servers you want to connect to

Detailed Steps on how to create ssh keys in Lunix

This contains details steps on how to create your ssh key pairs and load them onto your servers.

Setting up SSH Keys (public and private key)  

Just a quick summary on how to use the ssh-agent so we can use ssh keys which are password protected.

[CLIENT “Main client your connecting from, holds the private key (id_rsa)”]
Under your local account, create your SSH key pair , by default it will create under your home directory a .ssh directory (hidden folder)

First run ssh-keygen

[simterm]

localuser@client:remotehost# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/localuser /.ssh/id_rsa):

/home/localuser /.ssh/id_rsa already exists.

Overwrite (y/n)? y

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/localuser /.ssh/id_rsa.

Your public key has been saved in /home/localuser /.ssh/id_rsa.pub.

The key fingerprint is:

cc:1e:55:ad:44:fe:51:3d:c6:7a:5b:e4:9a:e2:fa:f6  localuser@remotehost

[/simterm]

Within this directory after running the command ssh-keygen , you will find your SSH key pair

[simterm]

localuser@remotehost# ls -al .ssh

total 20

drwx—— 2 wz7052 techsup 4096 Oct 21 13:27 .

drwx—— 3 wz7052 techsup 4096 Oct 21 13:41 ..

-rw——- 1 wz7052 techsup 1743 Oct 21 13:36 id_rsa   <– private key

-rw-r–r– 1 wz7052 techsup  425 Oct 21 13:36 id_rsa.pub  <– public key

[/simterm]

[SERVER “Server you want to connect to, holds the public key (id_rsa.pub)”]

We use a useful copy feature to push the keys onto the server we want to connect to, but we need to create the hidden .ssh folder in our home directory.

Create a .ssh directory under your home directory , make sure the permission are set to 700:

[simterm]

cd ~

mkdir .ssh

chmod 700 .ssh

[/simterm]

Repeat for each server you want to connect to.

[CLIENT “Main client your connecting from”]

Logon as yourself.

Copy the id_rsa.pub (the public key to the host you want to connect to)

[simterm]

ssh-copy-id -i .ssh/id_rsa.pub user@remotehost

[/simterm]

You will be prompted for your password on the remote host, and then it will push the key to your ~/.ssh directory and set up everything – saves a LOT of hassles instead of manually copying the file to the client!

Making it all work

[CLIENT “Main client your connecting from”]

Passphrase Log onto server

So now it is all configured and pushed onto each client you wish to connect to, you logon as yourself on the client.

ssh to the server you want to connect to:

[simterm]

ssh server

since ssh is smart it will see you have a public key present and ask for your passphrase:

Enter passphrase for key ‘/home/localuser/.ssh/id_rsa’:

Last login: Tue Oct 21 13:43:12 2014 from 172.22.1.138

[/simterm]

Passphrase auto Log onto server

Now we have this key loaded on many hosts and we don’t want to put in the password all the time.

To get around this , preload the the ssh-agent on the primary host and load the private key.

It will ask for the key password but as long as you run commands from this ssh session it will automatically provide the passwords to the remote hosts.

Let me show you

Load ssh-agent shell

[simterm]

localuser@client# ssh-agent /bin/bash

Add your private key to the agent

[localuser@client ~]$ ssh-add ~/.ssh/id_rsa

Enter passphrase for /home/localuser/.ssh/id_rsa:

Identity added: /home/localuser/.ssh/id_rsa (/home/localuser/.ssh/id_rsa)

[/simterm]

Now you should not need the password again when connecting to the remote host:

[simterm]

[localuser@client~]$ ssh server

Last login: Tue Oct 21 14:17:07 2014 from 171.22.12.138

[localuser@server~]$

[/simterm]

You see it used the password kept by the ssh-agent.

Running remote commands

Now you can use key pair to run commands on the other side.

[simterm]

ssh -q 10.11.0.92 hostname

server

[/simterm]

I have written a script that loops a bunch of servers IPs defined in hostlist.txt to run a simple hostname command in this script:

[simterm]

cat hostlist.txt

server1

server2

server3

server4

server5

[/simterm]

Script to gather hostname list and ensure that all the remote systems are connecting from the defined list:

[simterm]

cat hostname.sh

ssh-agent /bin/bas

ssh-add ~/.ssh/id_rsa

for host in `cat hostlist.txt`; do ssh -q $host hostname >> ssh-testrun ; done

wc -l hostlist.txt ; wc -l ssh-testrun

[/simterm]

Run the script and you should see all 5 servers defined in hostlist.txt match the connect output in ssh-testrun:

[simterm]

./hostname.sh

5 hostlist.txt

5 ssh-testrun

[/simterm]

Summary

You can see that creating ssh keys can be a powerful tool to easily connect to remote systems and also run remote health checks and gather data.

The post create ssh key appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/create-ssh-key/feed/ 0
How to set the grub password in CentOS 7 https://www.myrandomtips.com/linux/centos7/set-grub-password-centos7/ https://www.myrandomtips.com/linux/centos7/set-grub-password-centos7/#respond Wed, 04 Oct 2017 12:29:18 +0000 https://myrandomtips.com/?p=318 Cent OS 7 and most other Linux distributions use the GRUB2 boot loader. This guide shows you How to set the grub password in CentOS 7 and test it. The GRUB Menu can be protected by a password and this guide shows you how to set the grub password in CentOS 7. What is GRUB2?… Read More »

The post How to set the grub password in CentOS 7 appeared first on My Random Tips.

]]>
How to set the grub password in CentOS 7 Featured Image

Cent OS 7 and most other Linux distributions use the GRUB2 boot loader. This guide shows you How to set the grub password in CentOS 7 and test it. The GRUB Menu can be protected by a password and this guide shows you how to set the grub password in CentOS 7.

What is GRUB2?

This menu shows you all the installed it was first invented by Sir Erich Stefan Boleyn in the year 1995. GRUB2 bootloader is used to load the kernel and the kernel loads the Operating System, In short GRUB is the Module which is used to start the Operating System.

These 4-steps are how to set the grub password in CentOS 7:

  1. Create an Encrypted Password using  grub2-mkpasswd-pbkdf2
  2. Define Encrypted Password in /etc/grub.d/40_custom
  3. Refresh /boot/grub2/grub.cfg by grub2-mkconfig -o /boot/grub2/grub.cfg
  4. Test new password on Boot

YouTube Tutorial

Detailed Steps on setting the grub password in CentOS 7

Create an Encrypted Password

Create a password using the grub2-mkpasswd-pbkdf2 command:

[simterm]
# grub2-mkpasswd-pbkdf2

[root@centos7 grub.d]# grub2-mkpasswd-pbkdf2

Enter password:

Reenter password:

PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.440B11FE0ECAC09C69B18DD358758957HHIUH5EFC1F772E4D0F0F9E1005908EB2DDAECDA8D5975EBD594A89EF60697128C2631515992365958CDD61E3C3896E53.8789479587HFD79A57D46205EE9F4419B921598B8C05C593F12JOIJIO9271825279BBCD0C67AF810B961C91A8C8EB5D65127D3D3515292C6172F8E64

[/simterm]

Add the Encrypted Password to the Custom Configuration File

Make a copy of the text after your password is, we could add this directly in the main configuration file grub.cfg, but it is recommended not to edit directly so we put it into the /etc/grub.d/40_custom file it is good practice to make a backup copy of the file in case.

Then we can add that password into the /etc/grub.d/40_custom file:

[simterm]

# cp /etc/grub.d/40_custom /etc/grub.d/40_custom.backup

# vi /etc/grub.d/40_custom   # Edit the GRUB Custom Menu

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the ‘exec tail’ line above.

set superusers=”root”
password_pbkdf2 root grub.pbkdf2.sha512.10000.440B11FE0ECAC09C69B18DD358758957HHIUH5EFC1F772E4D0F0F9E1005908EB2DDAECDA8D5975EBD594A89EF60697128C2631515992365958CDD61E3C3896E53.8789479587HFD79A57D46205EE9F4419B921598B8C05C593F12JOIJIO9271825279BBCD0C67AF810B961C91A8C8EB5D65127D3D3515292C6172F8E64

[/simterm]

Update the grub.cfg File

Now we have added a new line into the grub file we need to refresh the grub.cfg file by using grub2-mkconfig command, and it is good practise to make a backup of grub.cfg file in case.

An then run the grub2-mkconfig to update grub.cfg file:

[simterm]

cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.backup

grub2-mkconfig -o /boot/grub2/grub.cfg

[/simterm]

We can confirm our password has been added into the GRUB2 Bootloader by cating the grub.cfg file:

[simterm]

cat /boot/grub2/grub.cfg

BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the ‘exec tail’ line above.

set superusers=”root”
password_pbkdf2 root grub.pbkdf2.sha512.10000.2F74BCD26B934CCD43446688BCB4D365862C8BD24461AC04D711F0403993D7571D056788565FAECCEE29B77141F070039A73F9C956DE532F98F93E819C4E842D.67ED723C2F6C4DAF8D42F26942228F678437E8F8569132C93439DF15C855FDBDA742226486

END /etc/grub.d/40_custom ###

[/simterm]

Testing the password

Reboot the system

[simterm]

# reboot

[/simterm]

During the boot process hit SPACE BAR at the GUB menu and hit e to edit the GRUB.

Image of CentOS 7 GRUB2 Menu

Enter in your Username and Password you defined before:

how to set the grub password - CentOS 7 GRUB2 Password Prompt

If the password works you will be able to edit the GRUB2 line entry as per screenshot:

how to set the grub password - CentOS 7 GRUB2 Edit Menu Entry

So that is how we can protect the GRUB2 Bootloader in CentOS 7.

The post How to set the grub password in CentOS 7 appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/centos7/set-grub-password-centos7/feed/ 0