Skip to main content

Posts

Showing posts from 2024

Linux find files that requires sudo or root access

Root access on a Linux operating system is needed, if you need to maintain the server or if something goes wrong and requires some changes that only root account is able to do. However, sudo can be used to give certain access to files that can be managed by specific users. For example, for whatever reason the system requires changing the DNS server IP address. Then sudo can be used to grant editing privileges to /etc/resolv.conf If just curious what are the files that require sudo or root access, on a Linux VM or server. Find command be used to locate or identify files that requires root privileges. On Linux VM, by typing: sudo id root This will show the output below: uid=0(root) gid=0(root) groups=0(root) The output shows that the user id for root is 0, and it's the same with group id and any other groups. Technically, 0 (zero) is the id for any files on the Linux system that is owned by root or requires root to modify or make some changes. For example, by typing: cd...

PowerShell execute multiple task on different servers

If you find yourself feeling overwhelmed by the maintenance of hundreds or multiple servers, there is no need for concern; PowerShell can assist you, provided that you have a clear understanding of the required actions. Below is a PowerShell code snippet that can shut down a server, restart a server, restart a service, or stop a service. It is advisable not to attempt this in a production environment unless the necessary actions are permissible and the task has been approve. An example image illustrating the output of the PowerShell script is included below. Ensure to modify the server name or service name as appropriate. And most importantly, used an elevated PowerShell with Admin credentials. Here's the PowerShell code: $servers = @("Admin_server", "DB_Server", "Redis_Server", "Docker_server") $action = @("Shutdown_server", "Restart_server", "Service_restart", "Service_stop") $ix = 0 ...

Linux: Displays Interface Status in Up or Down State

The `ip link show` command, available in more recent versions of Linux that support the `ip` command, provides information about network interfaces and their respective states. Executing `ip link show` yields extensive details regarding the interface, including its MAC address, operational state, IP address, and additional relevant information. The command below identifies the names of interfaces currently in either an UP or DOWN state. The output is piped to `grep` to filter and display only the state alongside the interface name. To display interfaces in a DOWN state, use the following command: ```ip command: echo "Interface on DOWN state: $(ip link show | grep "state DOWN" | grep -oP '^[0-9]+:\s+\K\S+' | cut -d: -f1)" ``` To display interfaces in an UP state, the command is: ```ip command: echo "Interface on UP state: $(ip link show | grep "state UP" | grep -oP '^[0-9]+:\s+\K\S+' | cut -d: -f1)" ``` The follo...

Windows 10/11: "This PC" in Windows Explorer is not displaying or missing

In Windows 10/11 the "This PC" icon, previously known as "My Computer" during the era of Windows XP, may unexpectedly vanish when accessing Windows Explorer or File Explorer. Microsoft has included a feature that allows users to either display or hide the "This PC" icon within the Navigation Pane. To control the visibility of the "This PC" icon, users should open File or Windows Explorer, navigate to the "View" dropdown menu, select "Show," and then click on "Navigation Pane." By default, the "Navigation Pane" option is enabled. If this option is disabled, the "This PC" icon will not be visible in File or Windows Explorer. In summary, if the "Navigation Pane" is enabled, "This PC" will be accessible; conversely, if it is disabled, "This PC" will not be displayed. Please follow image below on how to do it. Open File Explorer or Windows Explorer by pressing ...

How to select single click or double click to open a folders in Windows

How to change settings in Windows to single or double click to open folders or items in Windows 11 or Windows 10? The default in Windows is you need to double click on opening folders or files. However, an option is given on the system to change it to single click. Images below shows how to change the settings to single click or double click when opening items or folders in Windows. Open Windows Explorer by pressing "Windows key + E" or simply right click the Windows icon the four squares on the task bar and choose "File Explorer". Once the "File Explorer" opens click or select the "3 dots ..." on the bread crumbs bar or whatever its called. Please see image below on which one to click. After clicking the "3 dots" select "options" from the drop down menu that will appear on the screen. Please see image below for the guide. After selecting or clicking the "options" button, a Window will appear where you ...

PowerShell: Displaying Local Administrator Accounts

The PowerShell command provided below will enumerate all local accounts that belong to the Administrator group or possess administrative privileges on the system. Here is the PowerShell code to execute: Get-CimInstance Win32_GroupUser | Where-Object {$_.GroupComponent.Name -eq "Administrators"} | Select-Object -ExpandProperty PartComponent | Select-Object -Property Name Example Output: There are other ways to list user accounts with administrator privileges on a Windows System. On a server OS or other OS that supports Microsoft Management Console command will also show the list of users with admin rights, press "windows key + r" and when run box appears type: "lusrmgr.msc" or simply open a command prompt and type the command: "lusrmgr.msc", if the command is supported it will show a window where you can check the list of users with admin access. The MMC is beneficial because it features a graphical interface, but using scripts proves...

PowerShell to Verify BIOS Information

The BIOS Properties contain a wealth of information, with BIOS standing for Basic Input Output System. In technical point of view, a computer cannot start without the BIOS. While the computer may power on, it will only show a blank screen, and the operating system will not load or function or there will be no display. Here’s a straightforward PowerShell script to check details such as the BIOS release date, computer serial number, BIOS version, and additional information. PowerShell script to get BIOS information or data. $biosProperties = Get-WmiObject Win32_BIOS Write-Host "BIOS Name:" $biosProperties.Name Write-Host "BIOS Serial Num:" $biosProperties.serialnumber Write-Host "PrimaryBIOS:" $biosProperties.PrimaryBIOS Write-Host "BIOS ReleaseDate:" $biosProperties.ReleaseDate Write-Host "BIOS Version:" $biosProperties.BIOSVersion Write-Host "BIOS Caption:" $biosProperties.Caption Write-Host "BIOS Language...

PowerShell Get ComputerName

Getting computername in PowerShell is quite straight forward using environments variable. Example: $computerName = $env:ComputerName Write-Host "The computer name is: $computerName" With the right credentials and as long as WinRM or Windows Remote Management is enabled we can use the Environment ComputerName variable to shutdown a remote PC. This command runs or shutdown a remote pc, by invoking a local command to shutdown the PC. Invoke-Command -ComputerName remote_computer_name -ScriptBlock {Stop-Computer -ComputerName $env:ComputerName } The above invokes shutdown command locally, just like you were in front of the server or computer. Above is just a demonstration on how to use ComputerName environment variable. Shutting down a remote computer with a valid domain credentials, doesn't need the invoke-command instead command below can be used. Stop-Computer -ComputerName "RemotePC1", "Server2" -Force 1 Peter 5:6: "Humble y...

Linux get default gateway and assigned IP address

How to check default gateway and assigned IP address in Linux? There are quite a few ways to do this in a Linux system. However, in systemd or newer version of Linux systems which support the ip route command all the information is there already. The output of the ip route command shows the default gateway and the assigned or primary IP address of the VM or server. Here's an example to show the default gateway of a Linux system. The IP Address after the word "default via" is the default gateway of the system. Command is: ip r | grep default To show only the default gateway IP Address, we need to use RegEx and match the IPV4 address only. Here's the command: ip r | grep default | grep -Eoh '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' Sample output image: To show the assigned primary IP address on the VM or server, type the command below. Here's the command: ip r | grep -oP 'src \K\d+\.\d+\.\d+\.\d+' Sample output imag...

Postfix read or view the email in queue from the terminal window

Check or read the contents of the email on Terminal for troubleshooting purposes. The Postfix command below will show the entire original message with headers and body, or the email itself in raw format. Like reading email as a text file. Get or grab the postfix ID, by typing: mailq or postqueue -p Once the ID is known use the postcat command to view the contents of the ID. postcat -bh -q F0ABD910CDE33 | less ## this command will show the contents of the email that is on the queue To delete an email use the command below: postqueue -d ID ## delete the queue ID / delete the email with the specific ID, the email will be deleted on the queue used sparingly Proverbs 3:7 Do not consider yourself wise, fear God, and turn away from evil.

Check Chrony logs on.Linux

Chrony service maintains synchronizing with external time sources like NTP servers. In Redhat, Rocky or Alma Linux, Chrony logs can be checked using journalctl. Example: sudo journalctl -u chronyd -xe The output will be limited only to the.log or entries of Chronyd service. To check status of Chronyd, use systemctl status chronyd To further check any log entries pertaining to chronyd, browse to /var/log cd /var/log And type: egrep "*chrony*" . This will check all log entries that has the string chrony, include the dot at the end to check all files on the current path. You can examine those files.if need to troubleshoot further, or just view the configuration of Chrony for any misconfiguration such as typo error, or unsupported Chrony settings. To view the chrony configuration,.type: grep ^[^#] /etc/chrony.conf This will view only the configuration that are currently enabled or uncommented lines, and also remove any blank lines. chronyc sources -v  The above command will show ...

Linux clear logs or big files

To easily clear a log file or empty a big file. Type this on a terminal,.make sure to zip or backup the file if you feel you might need it later. > MyBigLog_file.txt Yes, just type greater than sign,.followed by the filename of a log file or any file. Don't do this in Production if not sure of the consequences. If the file exists it will empty the file, if the file doesn't exist it will create the file. Test it on a VM, to see what it really does before rolling out to production. Cheers,. enjoy Linux and command line. Be still and know God is in control!

Python create simple function

Basic function in Python. def multiply(x,y):   return x*y x=2 y=5 z=multiply(x,y) print("Product is: ", z) print(x, " * " , y ," is equals to = ", z) Sample output: That's it, a simple and basic functin in Python! Keep your feet on the ground! and kneel down to pray! Prayer is the ultimate connection to the creator.

How to trim leading and trailing spaces

How to trailing spaces, leading space or both on a CSV file or any text file? Notepad++ can easily do this task without any fuss. Can be done easily in 3 clicks, provided you have Notepad++ installed on your system. Notepad++ can easily be downloaded just search Notepad++ on your favorite search engine. Or try visiting this link: https://notepad-plus-plus.org/downloads/v8.6.7/ If your file that needs to be trimmed with leading or trailing spaces or both is on CSV or in a text file format, just export it or copy to Notepad++. For the sake of clarity and for anyone of what's trailing or leading space means. Leading spaces, are the spaces that are inserted at the front of any string. Since spaces are typically not shown on any editor, unless some settings are set to on the editor to show the spaces.So, leading spaces may appear like its not align to the left or beginning of any editor. While trailing spaces, appear at the end of the string. One way to check if the string has ...

Linux VM always disconnected after a few seconds or minutes

VM on VMware or vSphere always got disconnected after a few seconds or minutes. CentOS or RHEL VM cannot be accessed via SSH and unable to activate or make the Interface UP. Typing: ip link show nmcli dev status nmcli gen staus Shows that VM interface is not yet UP. Typing: ip link set ens192 up Will bring the interface UP but still SSH is not working and not able to reach the VM. Typing: nmcli con up ens192 Shows "STATE" connecting but will never shows "connected". Restarting the VM and creating new interface will not help either. Typing: nmtui (network manager text user interface) It shows that the interface has been assigned with correct IP Address, DNS and Gateway But the VM still not available on the network and SSH cannot access to the VM. Well the solution, might just be an overlooked by configuring so fast the VM that a simple option was not carefully set. If the VM was set with IP Address, DNS and Gateway manually, however, ...

How to get assigned ESXi license on vCenter

There are few ways to get the assigned license to a host on vCenter, it could be done via ESXi Shell, PowerCLI, or via License Administration. However, it can be also done via Host Inventory option. Click "Inventory" option and select the host in which you want to check or verify on what is the License Key assigned to the particular host. After selecting or clicking the host, go to the "Configure" tab option. Click and expand the "System" drop down menu and click "licensing", then the license key details that has been assigned or applied to the host will be shown on the right pane on the same window. The "License" will be the name that was assigned to the License Key like, "License for Server1", or "Nginx Host License Key" it can be any name that was created by the administrator, descriptive name that can easily identify the server or host is much better. And the "License Key" is the details of ...

How to run a command after x minutes

In Linux command below will trigger an rm commands after 5 minutes. echo "sleep 5m && rm -f /var/www/html/products.html" | at now In Windows the command below will also trigger a copy command after 5 minutes. Start-Job -ScriptBlock { copy /html/update.html /shared/} -ArgumentList (New-TimeSpan -Minutes 5)

Windows delete recent items history

How to delete "recent windows items" or the links of the files you've open in Windows 10 or Windows 11? Here are the locations that will delete the windows recent items. Please test on a VM or any test device before applying to the actual computer or device. Make sure the output is what is expected. Open a command prompt and change directory to this locations: cd "%APPDATA%\Microsoft\Windows\Recent Items" cd %APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations cd %APPDATA%\Microsoft\Windows\Recent\CustomDestinations Yes, please test on a Virtual Machine before applying to a production laptop or computer. Cheers! Till next time. Do ASAP, Always Say A Prayer... Practice O.T.G. = Obedience To God Make time for Prayer and Meditation. Take time to kneel down and Pray! Practice F.IF.T.H (Firm In Faith Towards Heaven) Your attitude will depends your altitude, stay humble!

Linux change hostname without rebooting

Changing hostname in Linux without rebooting, is quite straight forward. Changing the hostname will also change the name on the Terminal prompt, and will be displayed beside the current login user on the system. Open a terminal window and edit /etc/hostname. Use vi, nano or even echo command to change the content or value of the hostname file. Then type this: sysctl kernel.hostname=new-hostname-office.internal After typing the command, if the new hostname doesn't appear yet. Disconnect from SSH and login again via SSH and the new name will be displayed. That's it, simple as that. If unsure, try on a VM before applying to production. And check whether the desired output is the expected result. Cheers! Till next time. Do ASAP, Always Say A Prayer... Practice O.T.G. = Obedience To God Make time for Prayer and Meditation. Take time to kneel down and Pray! Practice F.IF.T.H (Firm In Faith Towards Heaven) Your attitude will depends your altitude, stay humble!

Check TLS settings in IE properties

 IE Properties or Internet Explorer properties still plays a part on Windows 10 or even Window 11. For example, some VPN settings like TLS or Transport Layer Security still checks on IE Properties. How to access Internet Explorer or IE properties? If IE is not yet blocked on the corporate environment or active directory network, then press windows key + r and type, iexplore on the run box. This will open Internet Explorer. A better way to do this without opening IE itself, is to use the Control Panel applet. Press windows key + r to open run box. And on the run box windows type, inetcpl.cpl and click ok or pres enter to run the command. This will open the IE or Internet Explorer properties and changes can be made. The other way is to check the Windows Registry, but a word of caution don't play or change the registry if you're not sure of what you're doing as this might lead to corrupting your Windows OS. Anyway, if you want to try or experiment on a Windows VM that can be ...