Wednesday, August 31, 2022

Linux Setup Cheat Sheet III

In the previous post, we set up Ubuntu Linux on Windows and Mac OS/X using VirtualBox. Now we focus our set up on dedicated Ubuntu Linux workstation or Windows PC that has dual boot with Ubuntu Linux installed.

Let's check it out!

Account
Typically, during the installation process, an admin account is prompted to be created with username and password. However, follow these instructions to add new user account with admin access on Ubuntu Linux.
 adduser stevepro
 usermod -aG sudo stevepro
 id stevepro
 su - stevepro

Alternatively, manage user accounts from Settings | Users user interface to add new user account. Initially, the account user will use the default icon. Consider changing via Settings | Users | Picture | Select File.

Login
If, whenever you attempt to login, you get the Ubuntu black screen with flashing cursor then attempt this fix: Reboot computer and login as recovery mode. Once logged in again, download and install NVIDIA.run.

Checkout here and here how to install nVidia driver on Ubuntu Linux e.g. NVIDIA-Linux-x86_64-460.84.run
 sudo su
 cd Downloads
 ./NVIDIA.run

IMPORTANT
If you are running X server then you may get an error when trying to install NVIDIA.run while still logged in:
 Ensure you are logged out!
 sudo service lightdm stop
 sudo init 3
 ./NVIDIA...run
 sudo service lightdm start

In, Software Updater | Additional Drivers, ensure NVidia is set "Using X.Org X server" as alternative driver.


Graphics
Initially, video file formats like mp4 may result in black screen. If so then install all the Multimedia Codecs:
 sudo apt-get update
 sudo apt install ubuntu-restricted-extras

Ubuntu
Confirm the version of Ubuntu Linux installed on terminal with lsb_release -a. Upgrade now accordingly:
 sudo apt update && sudo apt upgrade
 sudo reboot command
 sudo apt install update-manager-core
 sudo do-release-upgrade
 sudo reboot
 lsb_release -a

Kernel
Mainline is graphical tool to install the latest mainline kernel in Ubuntu Linux. Install Mainline from Terminal:
 sudo add-apt-repository ppa:cappelikan/ppa
 sudo apt update
 sudo apt install mainline
 mainline --check
 mainline --list
Start | Ubuntu Mainline. From the User Interface now install / uninstall Ubuntu Linux versions seemlessly. Once Ubuntu Linux kernel has been updated confirm kernel new version with uname -r.

Diff Tools
On Windows PC, Tortoise Merge is handy tool to compare 2x files whereas WinMerge is handy tool that can compare 2x directories. Meld + KDiff3 are alternatives for Linux both installed from Ubuntu Software Center.

Meld
File | New Comparison. File comparison navigate to file 1. Directory comparison navigate to file 2. Compare.

KDiff3
Similar to WinMerge: A. Directory navigate to directory 1. B. Directory navigate to directory 2. Compare OK.

Disk Space
Use Ubuntu Linux Disk Analyzer utility to identify common locations which can be used to free up disk space:
 rm -rf ~/.local/share/Trash/*
 du -sh ~/.cache/thumbnails
 sudo du -h /var/lib/snapd/snaps
 sudo du -sh /var/cache/apt
 sudo apt-get autoclean
 sudo apt-get clean
 sudo journalctl --disk-usage
 sudo journalctl --vacuum-time=3d
Other utilities to identify excess storage include ncud and bleachbit both which can be sudo apt install[ed].

Find
Here are some simple but effective uses of the find command e.g. find all text in file that follows predicate:
 find -L . -type f -exec grep -HniI 'g++' {} \; > ~/Steven/gpp.txt

Another useful example is how to find all of the distinct file extensions in a particular folder hierarchy:
 find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

Shortcuts
 General  Minimize all windows  Ctrl + Alt + D
 gedit  Move prev tab  Ctrl + Alt + PgUp
 gedit  Move next tab  Ctrl + Alt + PgDown

SSH
Secure SHell [SSH] may not be enabled after Ubuntu Linux is installed. Therefore you may get the following:
 ssh stevepro@192.168.15.50
 ssh: connect to host 192.168.15.50 port 22: Connection refused

Server
Here is how to fix the Connection refused issue on port 22. On the destination server set up the following:
 # Make sure OpenSSH is installed
 # Install SSH
 # Check SSH service
 # Start SSH service
 sudo apt list --installed | grep openssh-server
 sudo apt install openssh-server
 sudo service ssh status
 sudo service ssh start

Client
On source client connect to Files | Other Locations | Connect to Server sftp://stevepro@192.168.15.50.
Also, ssh stevepro@192.168.15.50 should now work!

Mouse Scroll
After setting up new blue tooth mouse the default scroll was too slow. Therefore, install and set up lmwheel:
 sudo apt-get install imwheel

Create mouse.sh. Integrate the following shell script. Set execute permissions. Configure using ./mouse.sh.
#!/bin/bash
if [ ! -f ~/.imwheelrc ]
then
cat >~/.imwheelrc<<EOF
".*"
None,      Up,   Button4, 1
None,      Down, Button5, 1
Control_L, Up,   Control_L|Button4
Control_L, Down, Control_L|Button5
Shift_L,   Up,   Shift_L|Button4
Shift_L,   Down, Shift_L|Button5
EOF
fi
CURRENT_VALUE=$(awk -F 'Button4,' '{print $2}' ~/.imwheelrc)
NEW_VALUE=$(zenity --scale --window-icon=info --ok-label=Apply --title="Wheelies" --text "Mouse wheel speed:" --min-value=1 --max-value=100 --value="$CURRENT_VALUE" --step 1)
if [ "$NEW_VALUE" == "" ];
then exit 0
fi
sed -i "s/\($TARGET_KEY *Button4, *\).*/\1$NEW_VALUE/" ~/.imwheelrc # find the string Button4, and write new value.
sed -i "s/\($TARGET_KEY *Button5, *\).*/\1$NEW_VALUE/" ~/.imwheelrc # find the string Button5, and write new value.
cat ~/.imwheelrc
imwheel -kill

VNC Viewer
If you are transitioning from Windows to Linux you may like to remote desktop from Windows to Linux box.

Linux
Follow all instructions. Change Ubuntu desktop manager from GNOME to LightDM. Install X11VNC as service on Ubuntu. Launch Terminal and enter the following. When prompted, ensure you choose lightdm not gdm3:
sudo apt-get update
sudo apt-get install lightdm
sudo reboot
sudo apt-get install x11vnc

After installing LightDM, rebooting and installing X11VNC, configure x11vnc.service. Replace your password!
sudo gedit /lib/systemd/system/x11vnc.service

[Unit]
Description=x11vnc service
After=display-manager.service network.target syslog.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -forever -display :0 -auth guess -passwd REPLACE_WITH_YOUR_LOGIN_PASSWORD
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure

[Install]
WantedBy=multi-user.target

Finally, after configuring x11vnc.service, enter the following commands to complete the VNC Viewer setup.
systemctl daemon-reload
systemctl enable x11vnc.service
systemctl start x11vnc.service

systemctl status x11vnc.service
ip addr | grep 192                        # NOTE the IP address 192.168.1.X

IMPORTANT
Don't lock the screen as you won't be able to VNC back in! Change Settings | Privacy | Screen Lock to this:
Windows
Download and install VNC Viewer. Launch VNC Viewer. Setup Team. Choose File | New Connection. Enter the IP address from above on port 5000 for VNC Server e.g. 192.168.1.X:5900. Enter friendly name + Connect.

When prompted choose Continue. Enter password | Check Remember password. Unfortunately not all keys may work e.g. Caps Lock. Also, you may have to disable and re-enable Repeat Keys from Universal Access.

Summary
Now we have a dedicated Ubuntu Linux workstation set up we are all set for cloud computing development!

No comments:

Post a Comment