Monday, August 21, 2023

JPG, PNG and PDF to text with Tesseract OCR

sudo apt install tesseract-ocr -y

sudo nano batch_ocr.sh

#!/bin/bash # Set the source and output directories source_dir="/path/to/source/folder" output_dir="/path/to/output/folder" # Loop through image and PDF files in the source directory for file in "$source_dir"/*.jpg "$source_dir"/*.png "$source_dir"/*.pdf; do filename=$(basename "$file") base="${filename%.*}" # Perform OCR using Tesseract tesseract "$file" "$output_dir/$base" -l eng done

chmod +x batch_ocr.sh

https://linuxhint.com/install-tesseract-ocr-linux/

Cannot empty Trash folder on Kubuntu Linux

Delete trash metadata files and let the system recreate them:

rm -r ~/.local/share/Trash/files/*

rm -r ~/.local/share/Trash/info/*

Win + E => Trash => F5

Check proxy server on Kubuntu Linux

curl -v -x 136.144.178.240:80 http://www.google.com

*   Trying 136.144.178.240:80...
* Connected to 136.144.178.240 (136.144.178.240) port 80 (#0)
> GET http://www.google.com/ HTTP/1.1
> Host: www.google.com

Transparent (NOA - No anonymity), Anonymous (ANM), Highly Anonymous (HIA).

Logging and Monitoring: Proxy servers can log and monitor the traffic passing through them. This means that the administrators of the proxy server can potentially see the websites you visit, the data you send and receive, and other activities.

SSL/TLS Decryption: Some proxies, known as "transparent proxies" or "man-in-the-middle proxies," have the ability to decrypt and re-encrypt secure HTTPS traffic. This is often done by using SSL/TLS certificates that are installed on the proxy. While this can be used for legitimate purposes, it can also expose your encrypted data to the proxy server.

Content Filtering: Many organizations use proxy servers to enforce content filtering policies. This means that the proxy can analyze the content of web pages and block access to certain websites or types of content.

Caching: Proxy servers can cache frequently accessed web content to improve performance and reduce bandwidth usage. While caching itself doesn't necessarily intercept traffic, it can impact your browsing experience.

Authentication and Access Control: Proxies can require users to authenticate before they can access the internet. This authentication can also involve intercepting traffic to prompt for login credentials.

Malware Scanning: Some proxy servers are equipped with malware scanning capabilities to detect and block malicious content before it reaches the user's device.


Traffic Monitoring: ISPs have access to the data that flows through their network. They can monitor the websites you visit, the data you send and receive, and the services you use.

Data Logging: ISPs can log certain data about your online activities, including the times you connect to the internet, the IP addresses you interact with, and the amount of data you consume.

Deep Packet Inspection (DPI): Some ISPs use deep packet inspection to analyze the content of your internet traffic. This technology allows them to identify the type of content you're accessing, which can be used for various purposes including traffic shaping and enforcing policies.

Traffic Shaping: ISPs can prioritize or throttle certain types of traffic based on their policies. For example, they might throttle video streaming to manage network congestion.

Censorship and Filtering: In some regions, ISPs might be required to block access to specific websites or content. They can also implement content filtering for various reasons.

DNS Requests: ISPs handle your Domain Name System (DNS) requests, which means they know which websites you're trying to access even if the actual content is encrypted.

Security Measures: Some ISPs offer security services that can help protect users from malicious websites and content. These services might involve scanning the websites you access.

Sunday, August 20, 2023

Remove USBGuard on Kubuntu Linux

locate usbguard // uses a pre-built database to quickly find files by name

locate usbguard | sudo xargs rm -rf // remove everything containing "usbguard"

sudo find / -xdev -name "*usbguard*" -exec rm -r {} \; // remove all found

sudo apt remove usbguard -y

sudo apt purge usbguard -y

sudo updatedb

locate usbguard // now shows nothing

https://roussos.cc/2019/08/19/usbguard/

Saturday, August 19, 2023

Analyze network activity on Kubuntu in real-time

sudo tcpdump // command-line packet analyzer that captures network traffic in real-time

sudo tcpdump -w /path/to/log.pcap // pcap format is used by Wireshark

sudo tcpdump -i <interface> -l | tee /dev/tty | sudo tcpdump  -w /media/user/folder/tcpdump_log.pcap // problem with buffering while displaying real-time in terminal

sudo tcpdump -i <interface> | tee /dev/tty | sudo tcpdump -l -U -G 600 -w /media/user/folder/tcpdump_log-%Y%m%d%H%M%S.pcap // won't help

sudo tcpdump -l -i any | tee -a /media/user/folder/tcpdump_log-$(date '+%Y%m%d%H%M%S').pcap // works but creates incompatible file with Wireshark

tcpdump -l -i any -qn port 53 | tee -a /tmp/dnslogs

sudo nano capture_traffic.sh

#!/bin/bash

# Set the path for the pcap file
PCAP_PATH="/media/user/directory/tcpdump_log-$(date '+%Y%m%d%H%M%S').pcap"

# Run tcpdump to capture traffic and display in terminal, saving to file in background
sudo tcpdump -i enp -l -w "$PCAP_PATH" &

# Run tcpdump to capture traffic and display in terminal
sudo tcpdump -i enp -l | tee /dev/tty

sudo chmod +x capture_traffic.sh

./capture_traffic.sh

sudo apt install wireshark // graphical network protocol analyzer

Ctrl + Shift + P =>Name Resolution => Resolve network (IP) addresses // in Wireshark

sudo dhclient

ping 8.8.8.8

ip link

nmcli

nmcli dev status

sudo lshw -class network

netstat

route

ss // (Socket Statistics) network sockets, network connections and network interfaces

ss -t -a -n // all established TCP connections

ss -u -l -n // listening UDP sockets

sudo apt install traceroute

  • -n: Show IP addresses instead of resolving hostnames.
  • -m max_ttl: Set the maximum number of hops to reach the destination.
  • -q nqueries: Specify the number of probes per hop.
  • -w waittime: Set the timeout for each probe.

traceroute -n -m 30 -q 3 -w 2 www.google.com

Wednesday, August 16, 2023

Android phone administration on Kubuntu

lsusb

ls -al

usbguard list-devices 

usbguard allow-device 11

sudo apt install android-sdk-platform-tools android-tools-adb android-tools-fastboot -y

adb shell

sudo touch /etc/udev/rules.d/51-android.rules

sudo nano /etc/udev/rules.d/51-android.rules

SUBSYSTEM=="usb", ATTR{idVendor}=="1234", ATTR{idProduct}=="1234", MODE="0666", GROUP="plugdev"

sudo usermod -aG plugdev username

groups

getent group plugdev

sudo udevadm control --reload-rules

adb kill-server

adb start-server

If not working, restart PC.


adb shell dumpsys battery

Current Battery Service state:
 AC powered: false
 USB powered: true
 Wireless powered: false
 status: 5
 status: 4
 health: 2
 present: true
 present: false
 level: 100
 level: 50
 scale: 100
 voltage: 4219
 temperature: 320
 technology: Li-ion

adb shell getprop // list of properties related to the device

adb shell getprop | grep "ro.product.model"

adb shell dumpsys iphonesubinfo 

Phone Subscriber Info:
 Phone Type = GSM
 Device ID = <IMEI>

adb shell ls // list all phone content

adb shell ls folder_or_file

adb pull /folder /destination/folder // copy files from phone


https://linuxhint.com/install-use-adb-fastboot-ubuntu/

https://developer.android.com/studio/run/device

Monday, August 14, 2023

Cleanup thumbnails in .cache/thumbnails on Kubuntu

touch /home/user/thumbnail_cleanup.sh

#!/bin/bash

THUMBNAILS_DIR="/home/user/.cache/thumbnails/large"
SIZE_LIMIT_MB=100 # Set the size limit in megabytes

while true; do
current_size=$(du -m "$THUMBNAILS_DIR" | cut -f1)
if [ "$current_size" -gt "$SIZE_LIMIT_MB" ]; then
find "$THUMBNAILS_DIR" -type f -mtime +7 -delete
fi
sleep 86400 # Sleep for 24 hours
done

chmod +x /home/user/thumbnail_cleanup.sh // make script executable

touch /home/user/.config/autostart/thumbnail_cleanup.desktop

[Desktop Entry]

Name=large thumbnail cleanup script

Type=Script

Exec=/home/user/thumbnail_cleanup.sh

Tuesday, August 8, 2023

Install Python3.11 for Stable Diffusion after Python.310

If you upgraded to python3.11* on Linux => No module named pip error. 

Launching launch.py...
################################################################
Using TCMalloc: libtcmalloc_minimal.so.4
Python 3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0]
Version: v1.5.1
Commit hash: 68f336bd994bed5442ad95bad6b6ad5564a5409a
Installing torch and torchvision
/home/user/Downloads/stable-diffusion-webui/venv/bin/python3: No module named pip
Traceback (most recent call last):
 File "/home/user/Downloads/stable-diffusion-webui/launch.py", line 39, in <module>
   main()
 File "/home/user/Downloads/stable-diffusion-webui/launch.py", line 30, in main
   prepare_environment()
 File "/home/user/Downloads/stable-diffusion-webui/modules/launch_utils.py", line 311, in prepare_environment
   run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True
)
 File "/home/user/Downloads/stable-diffusion-webui/modules/launch_utils.py", line 113, in run
   raise RuntimeError("\n".join(error_bits))
RuntimeError: Couldn't install torch.
Command: "/home/user/Downloads/stable-diffusion-webui/venv/bin/python3" -m pip install torch==2.0.1 torchvision==
0.15.2 --extra-index-url https://download.pytorch.org/whl/cu118
Error code: 1

sudo apt install python3-venv python3-pip

Delete venv folder in Stable Diffusion installation:

/home/user/Downloads/stable-diffusion-webui/venv/

./webui.sh --xformers

Stable Diffusion will install everything, it needs into new venv folder.

On Windows no need to do this. Use python3.10.6.

https://bobbyhadz.com/blog/python-no-module-named-pip

USB Type-C fast charging on Kubuntu not working

sudo dmesg | grep usb

sudo lsusb -v

sudo lsusb -v | grep -i power

sudo service udev status

sudo service udev restart

The file or folder udi=/org/kde/solid/udev/sys/devices/pci0000:00/0000:00:01.3/0000:03:00.2/0000:16:08.0/0000:25:00.0/usb3/3-1 does not exist.

sudo apt reinstall udev // no effect

sudo usbview

apt list libusb*

sudo apt install libusb-0.1-4

Actually problem is even with MTP transfer. Do not forget to allow phone via USBGuard!

https://www.cyberciti.biz/security/how-to-protect-linux-against-rogue-usb-devices-using-usbguard/

MTP tranfer works with old 2014 Android smartphone, with 2022 phone do not, but if you allow 2022 phone via USBGuard, at least charging starts working properly.

sudo apt reinstall mtp-tools // no effect

mtp-detect

libmtp version: 1.1.20


Listing raw device(s)

Device 0 (VID=**** and PID=****) is a Samsung Galaxy models (MTP).

   Found 1 device(s):

   Samsung: Galaxy models (MTP) (****:****) @ bus 3, dev 2

Attempting to connect device(s)

libusb_get_active_config_descriptor(1) failed: No data available

no active configuration, trying to set configuration

libusb_get_active_config_descriptor(2) failed: No data available

LIBMTP PANIC: Unable to initialize device

Unable to open raw device 0

OK.


usbguard list-devices

usbguard allow-device 17

sudo dmesg

Problem was in USBGuard settings. After removal of USBGuard everything works OK.

Sunday, August 6, 2023

No network connection on Kubuntu Plasma Desktop

sudo dhclient

ping 8.8.8.8

ip link

nmcli

nmcli dev status

sudo apt install plasma-nm

sudo apt install network-manager

sudo nano /etc/NetworkManager/NetworkManager.conf // didn't work out

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false

[device]
wifi.scan-rand-mac-address=no

change the line managed=false to managed=true // no effect

Add following:

[keyfile]

unmanaged-devices=none; OR for multiple devices

unmanaged-devices=none;your-device-name; // device name => ls /sys/class/net || ip link || nmcli

sudo service network-manager restart // didn't work

sudo systemctl restart NetworkManager

Failed to restart network-manager.service: Unit network-manager.service not found.

sudo apt reinstall network-manager

systemctl status NetworkManager

nmcli dev show // make sure device is managed

Reset Network Device Configuration:

sudo ifconfig device-name 0.0.0.0 down // didn't work

sudo ip addr flush dev device-name // didn't work

/etc/network/interfaces && /etc/sysconfig/network-scripts/ // Network Configuration Files

nmcli con show // list all existing NetworkManager connections names

nmcli con mod "Wired connection 1" ipv4.addresses ''
nmcli con mod "Wired connection 1" ipv4.gateway ''
nmcli con mod "Wired connection 1" ipv4.dns ''

nmcli con show 'Wired connection 1'

sudo systemctl restart NetworkManager

nmcli dev show  // look for state change

BEFORE => GENERAL.STATE:                          10 (unmanaged)

NOW => GENERAL.STATE:                          100 (connected (externally))

SOLVED! => NM works and connection is UP from the start

Reinstall drivers on Kubuntu in recovery mode

Ubuntu keyboard and mouse drives fail after upgrade:

sudo apt-get install -y xserver-xorg-input-all // reboot => also may solve other problems


sudo apt install nvidia-settings

If no internet connection in recovery mode or on Plasma Desktop

nmcli dev status

ping 8.8.8.8

sudo dhclient

Troubles with smartphone detection and other USB issues:

sudo apt reinstall mtp-tools

sudo apt reinstall libmtp*

sudo apt reinstall usb*

Network manager problems:

sudo apt install plasma-nm

sudo apt install network-manager

Show current Linux kernel name:

ls /boot

uname -r

uname -r -s -m -p -i -o

Linux 5.15.0-46-generic x86_64 x86_64 x86_64 GNU/Linux 

Reinstall Linux kernel:

sudo apt-get install linux-image-extra-$(uname -r)

Remove unused Linux kernel:

dpkg --list | grep linux-image // display a list of installed Linux kernel packages

sudo apt remove linux-image-5.4.0-90-generic // remove unused kernel

sudo apt remove linux-headers-VERSION*

sudo apt remove linux-modules-VERSION*

sudo apt remove linux-extra-VERSION*

Show info about system devices:

lscpu

lsblk

lsusb

lspci

sudo lshw

Saturday, August 5, 2023

Adding Python deadsnakes ppa repository on Kubuntu Linux

apt-cache policy python3

sudo add-apt-repository ppa:deadsnakes/ppa

https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa

MAKE SURE your Linux version is supported: https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/dists/

IF NOT, use latest supported version for ppa


sudo nano /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-jammy.list

deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ focal main
deb-src https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ focal main


sudo apt edit-sources // edit repositories

sudo nano /etc/apt/sources.list // edit repositories

ls /etc/apt/sources.list.d // list additional repositories files


/etc/apt/sources.list.d$ sudo dpkg --force-depends --purge libpython3.10-stdlib
dpkg: libpython3.10-stdlib:amd64: dependency problems, but removing anyway as you requested:
python3.10 depends on libpython3.10-stdlib (= 3.10.7-1ubuntu0.4).

(Reading database ... 254967 files and directories currently installed.)
Removing libpython3.10-stdlib:amd64 (3.10.7-1ubuntu0.4) ...
/etc/apt/sources.list.d$ sudo dpkg --force-depends --purge libpython3.10
dpkg: warning: ignoring request to remove libpython3.10 which isn't installed
/etc/apt/sources.list.d$ sudo dpkg --force-depends --purge libpython3.10-minimal
dpkg: libpython3.10-minimal:amd64: dependency problems, but removing anyway as you requested:
python3.10-minimal depends on libpython3.10-minimal (= 3.10.7-1ubuntu0.4).

(Reading database ... 254625 files and directories currently installed.)
Removing libpython3.10-minimal:amd64 (3.10.7-1ubuntu0.4) ...
Purging configuration files for libpython3.10-minimal:amd64 (3.10.7-1ubuntu0.4) ...
/etc/apt/sources.list.d$ sudo dpkg --force-depends --purge libpython3.10
dpkg: warning: ignoring request to remove libpython3.10 which isn't installed


/etc/apt/sources.list.d$ sudo apt install python3.10
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
python3.10 : Depends: python3.10-minimal (= 3.10.12-1+focal1) but 3.10.7-1ubuntu0.4 is to be installed
             Depends: libpython3.10-stdlib (= 3.10.12-1+focal1) but it is not going to be installed
python3.10-minimal : Depends: libpython3.10-minimal (= 3.10.7-1ubuntu0.4) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

sudo apt purge python3.10

sudo apt purge python3.10-minimal


sudo aptitude

https://packages.ubuntu.com/kinetic/libpython3.10-stdlib

sudo dpkg -i libmpdec3_2.5.1-2build2_amd64.deb

sudo dpkg -i libpython3.10-minimal_3.10.7-1ubuntu0.4_amd64.deb

sudo dpkg -i libpython3.10-stdlib_3.10.7-1ubuntu0.4_amd64.deb

sudo apt --fix-broken install


Spent lot't of time and failed...

Change the Python3 default version in Ubuntu

cd /usr/bin

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1

sudo update-alternatives --config python // choose python version

python3 --version

Python 3.10.7


sudo apt-get install --reinstall ca-certificates

See Technical details about this PPA => Signing key: => Fingerprint:

https://askubuntu.com/questions/1459362/how-to-resolve-the-key-not-available-error-on-deadsnakes-ppa

https://www.rosehosting.com/blog/how-to-install-and-switch-python-versions-on-ubuntu-20-04/

https://unix.stackexchange.com/questions/410579/change-the-python3-default-version-in-ubuntu

https://askubuntu.com/questions/1239829/modulenotfounderror-no-module-named-distutils-util

Problems and glitches in Mozilla Firefox

Enter key creates space instead sending prompt in Firefox. On Google search page in search field Enter key enters space. Firefox ESR on Kubuntu Linux. Solution:

In my case disabling AdBlocker extension solved the problem => Disable on this site option.

Remove python3 - Python 3.11 on Ubuntu

ls /usr/bin/python* // list all installed python versions

[Bug]: RuntimeError: Couldn't Install Torch

Stable Diffusion----------------------------------------------------------------------------
./webui.sh --xformers

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on user user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Using TCMalloc: libtcmalloc_minimal.so.4
Python 3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0]
Version: v1.5.1
Commit hash: 68f336bd994bed5442ad95bad6b6ad5564a5409a
Installing torch and torchvision
/home/user/Downloads/stable-diffusion-webui/venv/bin/python3: No module named pip
Traceback (most recent call last):
  File "/home/user/Downloads/stable-diffusion-webui/launch.py", line 39, in <module>
    main()
  File "/home/user/Downloads/stable-diffusion-webui/launch.py", line 30, in main
    prepare_environment()
  File "/home/user/Downloads/stable-diffusion-webui/modules/launch_utils.py", line 311, in prepare_environment
    run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
  File "/home/user/Downloads/stable-diffusion-webui/modules/launch_utils.py", line 113, in run
    raise RuntimeError("\n".join(error_bits))
RuntimeError: Couldn't install torch.
Command: "/home/user/Downloads/stable-diffusion-webui/venv/bin/python3" -m pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url https://download.pytorch.org/whl/cu118
Error code: 1
----------------------------------------------------------------------------Stable Diffusion

sudo rm /usr/bin/python3.11
sudo apt purge python3.11
usr/bin$ sudo apt remove python3.11-minimal

sudo find / -xdev -name python3.11*
sudo find / -xdev -name 'python3.11*' -exec rm -r {} \; // remove all found

sudo apt-get purge python3-uno
sudo apt-get install python3-uno

sudo apt-get purge python3.11-minimal python3.11 python3 python3-uno

sudo apt update -y && sudo apt upgrade -y
sudo apt --fix-broken install
sudo apt autoremove --purge *python* // remove all python packages

apt-cache policy python3

SOLUTION in my case:
sudo dpkg --force-depends --purge libpython3.11-stdlib
sudo dpkg --force-depends --purge libpython3.11
sudo dpkg --force-depends --purge libpython3.11-minimal
sudo apt --fix-broken install

AVOID creating conflicts by installing different kernel version updates!!!

sudo apt install -f --reinstall python3-minimal
sudo apt install -f --reinstall python3-pip
sudo apt install -f --reinstall python3
sudo apt update
sudo apt upgrade
sudo apt full-upgrade
sudo apt reinstall plasma-desktop
sudo apt reinstall kwin-x11

https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-programming-environment-on-ubuntu-22-04
https://askubuntu.com/questions/1402419/cant-remove-python-3-10-from-ubuntu-20-04lts
https://gist.github.com/zhensongren/811dcf2471f663ed3148a272f1faa957
https://computingforgeeks.com/how-to-install-python-on-ubuntu-linux-system/?expand_article=1
https://linuxhint.com/uninstall-python-ubuntu-22-04/
https://www.debugpoint.com/install-python-3-10-ubuntu/