Robert’s Linux Notes

My fstab
# /etc/fstab: static file system information.
#
# Use ‘blkid’ to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
UUID=da0cf23f-cb0d-443e-911a-36247b48f0d7 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=75445880-eb29-4784-a890-157ac38c4be1 none swap sw 0 0
# /mnt/bak was on /dev/sdb1 during installation
UUID=6ab84907-1cd0-4509-b8c5-4ae8c0b8e024 /mnt/bak ext4 defaults 0 2
# /mnt/store was on /dev/sdb2 during installation
UUID=a469e9cb-50fe-4f91-8615-78cd81fa7ba1 /mnt/store ext4 defaults 0 2
#
#
//10.1.1.10/store /mnt/fishmythstore cifs guest,nounix,user,uid=1000 0 0


Clean up old kernels in Linux Mint:-

This should remove all kernels except your current kernel and the two latest old ones:

sudo apt-get install byobu

sudo purge-old-kernels

Or you can do it via “Update Manager”


To Do before upgrading or changing distro:-
Save fstab, smb.conf
Save /home
Save packages which are possibly not in new version
Export bookmarks, addressbook and calendar
Check (and maybe save) password.pwm, cron.daily and cron.hourly stuff, VMWare image folder
Take note of sound settings


My PC – “Beast” (This box has been sold to friends)
(Parts from Dove – 6/4/11)
2x Adata 2GB DDR3 1333 DIMM 3yr wty Hynix/Micron/Major
Intel Core i5 2500 3.30GHz 6MB LGA1155 – HD GRAPHICS
Gigabyte GV-N220OC-1GI PCIE HDMI+DVI+VGA
Gigabyte GA-P67A-UD3-B3 ATX LGA1155
200Gb Western Digital SATA drive *8.9m/s *7200 RPM * 8Mb cache
200Gb Seagate Barracuda SATA Drive *7200 RPM * 8Mb cache
LG GSA-H30NS 18x Dual layer DVD-RW SATA drive
Acer AL1916W 1440 x 900 19″ diagonal (Wide Screen)
ViewSonic VX2439WM 1920×1080


To mount Shares from Windows PC’s
Create directory e.g /share
To mount…. type…

smbmount //winsys/winshare some-mount-point
Example for me (X = win pc, C = Share name)
smbmount //X/C /share
To unmount (my example)…
smbumount -t smbfs /share


Mounting smbfs Shares Permanently
http://www.justlinux.com/nhf/Filesystems/Mounting_smbfs_Shares_Permanently.html
And some notes I found useful to access Vista shares…..
Using a text editor, create a plain text file containing two lines:

username=windows_username
password=windows_password

Substitute your actual Windows username and password for the italicized text. Save the file in your home folder as .smbpasswd (don’t forget the dot at the beginning of the filename, which makes the file hidden). Finally, change the permissions on the file so only you can open and change it by issuing the following command in a Terminal window:
chmod 600 .smbpasswd

On the Linux machine, open /etc/fstab in a text editor.
(On Ubuntu, I used the command sudo gedit /etc/fstab. You can use another editor if you prefer.)

At the end of the file, add a new line containing the following:

//vista_pc_name/share_name mount_folder_name smbfs credentials=/home/linux_username/.smbpasswd,uid=linux_username,gid=users 0 0

Use the UNC path for the Windows share, and replace mount_folder_name with, for example, /mnt/vista_public).
Substitute your Linux username for the values in red. These credentials will be passed to the Vista machine.
(Note: there’s no space after the comma and before the uid and gid.)
[Update: Thanks to Jeremy Allison in the comments of the previous post for pointing out that smbfs is deprecated and no longer maintained. You can safely substitute cifs for smbfs in the fstab entry.]


Sitecopy
.sitecopyrc…..
site mysite
server fisherfamily.orconhosting.net.nz
username *******
password *******
local /home/robert/Shared/robert/my_web
remote ~/fisherfamily.orcon.net.nz/htdocs/

Maintenance
sitecopy –update sitename (or for the above)….
sitecopy –update mysite


Imagemagick

To resize…
# convert -sample 80×40 input.jpg output.jpg
for multiple files….
mkdir new
for n in *; do convert -sample blabla $n new/$n; done
where that asterisk stands for any shell glob pattern you wish to use to match the files to be converted (you can also use more than one pattern, space-separated).

For example…..
mkdir new
for n in *jpg; do convert -sample 80×40 $n new/$n; done

or
for n in *jpg; do convert -sample 400×400 $n new/$n; done

Someone else suggested…..
for x in *.jpg; do convert -sample 80×40 $x ${x/.jpg/640×480.jpg}; done

To rotate…
convert -rotate -90 dscf0010.jpg 10.jpg


Album
http://marginalhacks.com/Hacks/album/
To create captions file –
ls > captions.txt
You get a file with the names of all the pics in the directory, then edit it with your captions. Do it with the browser viewing the pics, and an xterm editing the file open at the same time.


WGET
Try wget, it is a commandline tool, but don’t be scared! It is very robust.
example:
wget http://www.microsoft.com/win2k.iso
if it stops part way through
wget -c http://www.microsoft.com/win2k.iso
-c = continue.
It will dump the file in your current directory.

I often cut and paste the file’s URL into a terminal window to save a lot of retyping.


SCP
To copy a file from where you are working to a remote machine, the command is
$> scp @:{}

where is optional. If the directory is not given after the colon, the file will be saved in your home directory.
The statement
$> scp foo.java blair@foo.clarku.edu:java
will save the file foo.java to my directory java/ on the machine foo.clarku.edu

To retrieve a file from a remote machine, the order is reversed:
$> scp blair@foo.clarku.edu:java/foo.java ./java

will bring foo.java from the java directory on foo and save it to the java directory where I am giving the scp command.
To save to the home directory the ./ is just a . /

Use -r for recursive copies e.g.
scp -r /localfile user@othercomputer:/otherfolder

My examples:-
scp -P xxx 60.234.134.181:Shared/robert/my_web/super15/week10.html .
(Note: The dot at the end means the current local directory. This is a handy trick that can be used about everywhere in Linux.)

scp -P xxx week10.html robert@60.234.134.181:Shared/robert/my_web/super15/


Various Linux Commands:-
cat /proc/bus/usb/devices
cat /proc/pci
cat /proc/modules
cat /proc/cpuinfo
cat /proc/ioports
cat /proc/sys/dev/cdrom/info
cat /proc/scsi/scsi
cat /proc/version


To Display Messages as they occur
tail -f /var/log/messages


To find Default Gateway:-
route -n
ip route show
netstat -rn


To show active internet connections:-
netstat -tlpn


To show DNS addresses
nmcli dev show | grep DNS


To Mount an iso image to see files….
mount -o loop -t iso9660


To see pci devices…
cat /proc/pci


To see Drives…
dmesg | grep hd
or
df


To find files or folders….
locate name
For case insensitvity use -i (locate -i filename)
locate name | less (e.g. locate icon | less)
locate name | most (e.g. locate icon | most)
locate name | grep another_name | most (e.g. locate icons | grep mozilla | most)
or
qpkg -l mozilla|grep icons|less
OR – finding files with specific text……
find dir | xargs (z)grep (e.g. find /etc | xargs grep GENTOO_MIRRORS=)
(the z is used for zipped files)


Creating executable script file
create a text file with
#!/bin/bash
as the first line then just add the command-line stuff you want.
Then when you are finished do:
chmod +x filename
to make it executable
then hey presto you have a script ready to run.


Backups with Linux and Rsync
http://www.mikerubel.org/computers/rsync_snapshots/


SSH on different port (normally 22)
For example – ssh ipcop -p 222


How to create Image (ISO) files from CD/DVD
Assuming that /dev/cdrom is the location of CD/DVD-ROM

sudo umount /dev/cdrom
readcd dev=/dev/cdrom f=file.iso
or
Turn a CD/DVD into an .iso
sudo umount /dev/cdrom
dd if=/dev/cdrom of=file.iso bs=1024
Turn a folder into an .iso
mkisofs -r -o file.iso /location_of_folder/
Generate an MD5 checksum file
md5sum file.iso > file.iso.md5


To test pop3 use telnet:
telnet pop3.xtra.co.nz 110
user xxxx
pass yyyy
list
quit


To set up my USB Portable Hard drive enclosure.
Create ntfs partion with
cfdisk /dev/sdc

Format ntfs partition with
mkfs.ntfs /dev/sdc1 -L portable (portable = volume name)

Mount drive (writable) with
mount -t ntfs-3g /dev/sdc1 /mnt/usbdrive/ -o force
(Having first created folder /mnt/usbdrive)
or for my pocket drive…..
mount -t ntfs-3g /dev/sdc5 /mnt/usbpocket/ -o force

My bak backup……
root@beast:~# rsync -urC –delete /mnt/bak/ /media/HP\ Pocket\ Media\ Drive/


To Install Webmin
First, you need to install the components Webmin needs.
This can be done with one command:
#aptitude install libnet-ssleay-perl libauthen-pam-perl libio-pty-perl libmd5-perl
When that is done, you need to download Webmin, the current version is 1.470.
You could simply go to the webmin website and download it
After it is downloaded, install it using dpkg:
#dpkg –install webmin_1.470_all.deb


How I installed Transmission on Ubuntu 16.04
(I followed http://www.htpcguides.com/install-transmission-bittorrent-client-on-ubuntu-15-x/)

sudo apt-get install transmission-cli transmission-common transmission-daemon transmission-gtk minissdpd
sudo service transmission-daemon status
sudo service transmission-daemon stop
sudo nano /var/lib/transmission-daemon/info/settings.json
sudo usermod -a -G debian-transmission robert
sudo service transmission-daemon start
sudo service transmission-daemon stop
sudo service transmission-daemon status
sudo mkdir -p /etc/systemd/system/transmission-daemon.service.d
sudo nano /etc/systemd/system/transmission-daemon.service.d/local.conf
sudo systemctl daemon-reload
sudo service transmission-daemon stop
sudo usermod -aG robert debian-transmission
sudo usermod -aG debian-transmission robert
sudo chmod 775 /etc/transmission-daemon/settings.json
sudo nano /etc/transmission-daemon/settings.json
sudo service transmission-daemon restart
sudo service transmission-daemon status


How I installed Google Drive on Linux Mint
google-drive-ocamlfuse
Don’t be frightened by the name, google-drive-ocamlfuse is a CLI fuse-based filesystem backed by Google itself, and with it you can perform directory operations on your Google Drive account.

It features syncing with multiple accounts, access to Google Drive’s trash directory, and read-only access to Google docs, sheets, and slides.

sudo apt-add-repository ppa:alessandro-strada/ppa
sudo apt-get update
sudo apt install google-drive-ocamlfuse
sudo groupadd fuse
sudo usermod -a -G fuse robert
exec su -l $USER
google-drive-ocamlfuse
mkdir ~/googledrive
google-drive-ocamlfuse ~/googledrive
mount

To disconnect manually:- fusermount -u ~/googledrive

To connect your googledrive manually:- google-drive-ocamlfuse ~/googledrive


How I set up Passwordless SSH
cd /home/robert/.ssh/
ls
rm id_rsa
rm id_rsa.pub
ls

ssh-keygen (Do not enter any passphrase. Just hit ENTER key and continue with default values.)
ssh-copy-id robert@123.456.789.123 -p 246
ssh-add
ssh-add -l

ssh robert@123.456.789.123 -p 246


Upgrading HASS (virtualenv)
sudo -u homeassistant -H -s
cd ~/.homeassistant/
cd /srv/homeassistant
python3 -m venv .
source bin/activate
(This step does not seem to work any more:- #pip3 install --upgrade homeassistant)
python3 -m pip install --upgrade homeassistant

Hass Crontab:-
10 2 * * * systemctl restart homeassistant.service
12 2 * * * systemctl restart nginx.service
0 1 * * 3 rm /home/homeassistant/.homeassistant/.google_maps_location_sharing.cookies


How I installed VNC on my Ubuntu 18.04.1 server
https://linuxconfig.org/vnc-server-on-ubuntu-18-04-bionic-beaver-linux
sudo apt update
sudo apt install vnc4server xfce4 xfce4-goodies

vncpasswd
vncserver (You will require a password to access your desktops.)
vncserver -kill :1
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
nano ~/.vnc/xstartup
Edit as follows:-
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
Save and make executable – sudo chmod +x ~/.vnc/xstartup
Start the server again – vncserver
netstat – tlpn (will show active connections)