Linux – Unable to execute basic Bash command

Essential Commands Not Found:

  • The ls command is missing, which is a basic utility in Unix-like systems.
  • The nautilus command is also not found, and attempting to install it resulted in further issues.

Shell Problem:

  • When attempting to switch to csh (C shell), the command is also unavailable.
  • This indicates that the shell environment is not properly configured or essential packages are missing.

General Package/System Issues:

  • The server might be in a minimal installation state or lacks critical tools and utilities.
  • It’s possible that the PATH environment variable is misconfigured, leading to the inability to locate standard system commands.

Dependency or Corruption:

  • If the server was recently updated or reconfigured, there may have been issues with the package manager or repository settings, leading to missing binaries.

Solution

Check PATH:

  • Run echo $PATH to verify if the environment paths are set correctly.
  • Typically, it should include paths like /bin, /usr/bin, /sbin, /usr/sbin.
  • nano ~/.bashrc
  • export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  • source ~/.bashrc

Reinstall Core Utilities:

  • Try running sudo yum groupinstall "Development Tools" or sudo dnf groupinstall "Development Tools" to restore essential utilities, assuming it’s Red Hat-based.

Ensure Package Manager Functionality:

  • Test if the package manager works: sudo yum update or sudo dnf update
  • If it fails, check for repository issues.

Inspect Shell Configuration:

  • Review the default shell configuration in /etc/passwd for the user rakesh.
  • Revert to bash or another functioning chsh -s /bin/bash username

Check System State:

  • Verify the integrity of installed packages sudo rpm --verify -a
  • Inspect system logs for errors: journalctl -xe

Reset a lost admin password in Ubuntu

Prerequisites

  • You have physical access to the machine or virtual console if using a virtual server.
  • The system is running Ubuntu or a similar Linux distribution.

Step 1: Reboot the System and Access GRUB

  • Restart your machine and hold down the Shift key as it boots up. This will bring up the GRUB bootloader menu. If GRUB doesn’t appear, it may be hidden by default, so make sure to press the Shift key early during the boot sequence.

Step 2: Enter Recovery Mode

  • In the GRUB menu, use the arrow keys to highlight the Ubuntu boot option.
  • Press e to edit the selected boot entry.
  • Find the line that begins with linux and ends with ro quiet splash. Continue the line with:
rw init=/bin/bash

This modification will boot the system with read/write permissions and open a Bash shell.

Step 3: Boot into Root Shell

  • After editing the GRUB entry, press Ctrl + X or F10 to boot with the modified settings. This will boot into a root shell without asking for a password.

Step 4: Reset the Admin Password

  • At the root prompt, type the following command to reset the admin password (replace username with your actual admin username):

passwd username

  • You will be prompted to enter a new password. Type the new password and confirm it when asked.

Important Note: Ensure the password meets the system’s complexity requirements (e.g., minimum length, special characters).

Step 5: Remount the Filesystem as Read-Only

  • Before rebooting the system, remount the filesystem as read-only to avoid filesystem corruption. Run the following command:

mount -o remount,ro /

Step 6: Reboot the System

  • Now reboot the system by typing:

reboot

Your system will restart, and you should now be able to log in with the newly reset admin password.
If you are unable to reboot, can just reset the system.

Powershell on Android Mobile (Userland)

The idea behind this is to install a Linux OS into your mobile and install powershell into the OS.

screenshot from PlayStore

Step 1 – Install and Run Userland.
Step 2 – Choose Ubuntu (18.04) – Enter username and Passwords, choose SSH

Wait a few minutes while loading filesystem

Step 3 – You will eventually see this. Login using ssh password entered before.

Step 4 – Do update and upgrade. (Press Y to agree to upgrade)
sudo apt-get update && sudo apt-get dist-upgrade

Setp 5 – Install wget
sudo apt-get install wget

Step 6 – Create a folder
mkdir ps
cd ps

Step 7 – Download latest release from https://github.com/PowerShell/PowerShell/releases/,
be sure to choose a powershell-xxx-linux-arm64.tar.gz.

wget https://github.com/powershell/powershell/relases/download/download/v7.0.3/powershell-7.0.3-linux-arm64.tar.gz

Step 8 – extract the files from tar.gz
tar -xzvf powershell-7.0.3-linux-arm64.tar.gz

Step 9 – Additional tools needed for this.
sudo apt-get install libunwind8 icu-devtools

Step 9 – type in ./pwsh in the /ps directory to run powershell.

Step 10 (optional) – Adding in PATH variable permanently.
Install file editor
sudo apt-get install nano

Verify the PATH of pwsh directory
sudo find / -name pwsh

Edit ~/.Profile
sudo nano ~/.Profile

Add in PATH=$PATH:/home/username/ps at the bottom of the page

Save and Exit (Ctrl + X)

Type in pwsh to run powershell after this.