Skip to main content

Posts

Showing posts from October, 2025

Add SSH keys to known-hosts in Linux

Setting up a new environment of Linux boxes either Physical servers, VMs or Containers, one thing to consider is how you will login or manage those devices. In Linux world, SSH is the most common way to manage headless servers or VMs. SSH keys must be added to ~/.ssh/known_hosts to preload to the host keys before connecting to the new servers. There quite a few ways to do it, via bash script, or simply logging in and copying manually the key.but quite tedious and not the practical way if there are hundreds of more servers. ssh-keyscan server1 server2 server3 >> ~/.ssh/known_hosts This will suppress the question whether you want to add the keys or not, and type yes to continue. ssh-keyscan won't require any manual intervention once the connectivity is established it will just add all the keys available on the remote servers to known_hosts. Yes rather than typing ssh-keyscan server1 server2 it would be better to have a list on a text file and use while loop to read the file and...

Linux Bash rename multiple files

Bash script/command below shows how to rename multiple files. If the filename shows some pattern, then it will be easier to rename.  Example filename: file_text_a.txt file_text_b.txt file_text_c.txt file_text_etc... ... .txt Script/command below, shows some magic to rename files all at once. The command below can be integrated to a script or simply run the command on the terminal. Create some dummy files for testing before running on actual files to be renamed or in production. find . -name "*.txt" -exec sh -c '   for file; do       newf=$(echo "$file" | sed "s/text/tested/" )  &&   mv "$file" "$newf"   done ' sh {} + Output is: file_tested_a.txt file_tested_b.txt Since the command uses sed, replace 'text' with any string to be searches and replace 'tested' also with any new string for the filename. Till next time.. Enjoy Linux and scripting... Put your trust in God and have Faith. Exodus 14:14, "The...