scripts – My Random Tips https://www.myrandomtips.com Useful Tips to Save Time Fri, 14 Mar 2025 20:17:59 +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 scripts – My Random Tips https://www.myrandomtips.com 32 32 Red Hat 9 LVM & XFS Setup https://www.myrandomtips.com/linux/red-hat-9-lvm-xfs-setup/ https://www.myrandomtips.com/linux/red-hat-9-lvm-xfs-setup/#respond Thu, 13 Mar 2025 06:43:03 +0000 https://www.myrandomtips.com/?p=1256 I’ve created a handy web-based tool for Red Hat 9 users to simplify setting up and managing LVM with XFS filesystems. Built with HTML, CSS, and JavaScript, this tool generates precise shell commands based on your inputs. You can specify disks (like sdb, sdc), choose to either create a new volume group (VG) or extend… Read More »

The post Red Hat 9 LVM & XFS Setup appeared first on My Random Tips.

]]>
I’ve created a handy web-based tool for Red Hat 9 users to simplify setting up and managing LVM with XFS filesystems. Built with HTML, CSS, and JavaScript, this tool generates precise shell commands based on your inputs. You can specify disks (like sdb, sdc), choose to either create a new volume group (VG) or extend an existing one, and define your VG and logical volume (LV) names. It also lets you set a custom mount point and decide whether to allocate all available space to the LV or a specific size (e.g., 10G). For a new VG, it initializes the disks, creates the VG and LV, formats it with XFS, mounts it, and even provides an /etc/fstab entry. For extending a VG, it adds new disks, grows the existing LV, and expands the XFS filesystem—all tailored to your setup. Just fill in the form, click “Generate Commands,” and copy the output to your terminal!

Red Hat 9 LVM XFS Deployment Tool

Red Hat 9 LVM & XFS Setup

This tool serves as a helpful guide for managing disk setups on Red Hat 9, offering clear, tailored LVM and XFS commands through an easy-to-use webpage. It’s designed to assist anyone needing to create a new volume group or extend an existing one, simplifying the process with step-by-step output. I’m thankful for the support of Grok 3, built by xAI, which was instrumental in developing this project. Its insights helped me craft the code and turn my concept into a practical guide—many thanks to Grok 3 for the assistance!

The post Red Hat 9 LVM & XFS Setup appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/red-hat-9-lvm-xfs-setup/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
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