Linux: Difference between revisions

No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
A collection of notes on using Linux systems.
A collection of notes on using Linux systems.
Notes here are for Ubuntu but should work on similar debian derivative distros.
Notes here are for Ubuntu but should work on similar debian derivative distros.
 
See also [[NixOS]].


==Basic Terminal Commands==
==Basic Terminal Commands==
Line 60: Line 60:
</syntaxhighlight>
</syntaxhighlight>


;Repositories
Repository sources are saved in
* A line in <code>/etc/apt/sources.list</code>
* A file in <code>/etc/apt/sources.list.d/</code>
Application desktop icons are stored in <code>/usr/share/applications/</code>.
The update notifications are in <code>/etc/apt/apt.conf.d/99update-notifier</code>. Comment these out to disable them.<br>
Unattended-updates are in <code>/etc/apt/apt.conf.d/50unattended-upgrades</code>.
{{hidden | dpkg |
===dpkg===
===dpkg===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 68: Line 80:
sudo dpkg -l | grep apache
sudo dpkg -l | grep apache
</syntaxhighlight>
</syntaxhighlight>
 
}}
{{hidden | yum |
===yum===
===yum===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 77: Line 90:
yum update
yum update
</syntaxhighlight>
</syntaxhighlight>
 
}}
===Repositories===
Repository sources are saved in
* A line in <code>/etc/apt/sources.list</code>
* A file in <code>/etc/apt/sources.list.d/</code>
 
Application desktop icons are stored in <code>/usr/share/applications/</code>.


==SSH==
==SSH==
Line 121: Line 128:


===Disable password authentication===
===Disable password authentication===
* Edit <code>/etc/ssh/sshd_config</code>
# Edit <code>/etc/ssh/sshd_config</code>
* Set <code>PasswordAuthentication</code> to <code>no</code>
# Set <code>PasswordAuthentication</code> to <code>no</code>
* Set <code>ChallengeResponseAuthentication</code> to <code>no</code>
# Set <code>ChallengeResponseAuthentication</code> to <code>no</code>
* Test by ssh'ing into the machine using <code>-o PreferredAuthentications=password -o PubkeyAuthentication=no</code>
# Test by ssh'ing into the machine using <code>-o PreferredAuthentications=password -o PubkeyAuthentication=no</code>


===Port Forwarding===
===Port Forwarding===
Line 177: Line 184:


===Driver Installation===
===Driver Installation===
* Run <code>ubuntu-drivers list</code> to get a list of drivers
# Run <code>ubuntu-drivers list</code> to get a list of drivers
* Install the latest driver
# Install the latest driver
** E.g. <code>sudo apt install nvidia-driver-460</code>
#* E.g. <code>sudo apt install nvidia-driver-460</code>
* If you have secure boot enabled, you will be asked for a password during installation
# If you have secure boot enabled, you will be asked for a password during installation
** This is because the driver is a DKMS module.
#* This is because the driver is a DKMS module.
** After installation, reboot your computer and select "Enroll MOK" and enter that password in.
#* After installation, reboot your computer and select "Enroll MOK" and enter that password in.
** '''Note''' Failure to do this will result in the driver not working
#* '''Note''' Failure to do this will result in the driver not working
* Validate your installation by running <code>nvidia-smi</code>.
# Validate your installation by running <code>nvidia-smi</code>.
** <code>nvidia-smi</code> shows the latest cuda version supported by the driver, not necessarily the cuda version installed.
#* <code>nvidia-smi</code> shows the latest cuda version supported by the driver, not the cuda version installed.


===Cuda Installation===
===Cuda Installation===
Line 442: Line 449:
==Dual Booting==
==Dual Booting==
===Fix time difference between Windows===
===Fix time difference between Windows===
[http://ubuntuhandbook.org/index.php/2016/05/time-differences-ubuntu-1604-windows-10/ Reference]
By default, Windows stores the local time in the hardware clock while Ubuntu stores UTC time.
 
Set ubuntu to store UTC time:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
timedatectl set-local-rtc 1 --adjust-system-clock
timedatectl set-local-rtc 0 --adjust-system-clock
</syntaxhighlight>
</syntaxhighlight>
Set Windows to store UTC time:
https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows


===Recover GRUB after installing Windows===
===Recover GRUB after installing Windows===
Line 679: Line 691:


==Encryption==
==Encryption==
For encrypting external drives, I recommend LUKS.<br>
For encrypting entire drives, I recommend LUKS.<br>
I do not recommend using Ubuntu's full disk encryption.<br>
If you want encrypt a directly, you can use fscrypt (ext4 only).
If you want to do encryption, just encrypt your home directory using fscrypt.
 
Note that ecryptfs is deprecated and shouldn't be used.


===Encrypt Home After Install===
===Encrypt Home After Install===
Line 732: Line 745:
;Notes and Caveats
;Notes and Caveats
* <code>systemd</code> will no longer have access to your home so all startup apps should be placed elsewhere
* <code>systemd</code> will no longer have access to your home so all startup apps should be placed elsewhere
** E.g. Move all startup scripts in your <code>~/bin</code> to <code>/usr/bin</code>
** E.g. Move all startup scripts in your <code>~/.local/bin</code> to <code>/usr/local/bin</code>
* <code>ssh</code> will not work until home has been decrypted since the authorized keys are in <code>~/.ssh/authorized_keys</code>
* <code>ssh</code> will not work until home has been decrypted since the authorized keys are in <code>~/.ssh/authorized_keys</code>


Line 784: Line 797:


==Network Troubleshooting==
==Network Troubleshooting==
On one of my OptiPlex5060 servers, the network adapter would reset on git ssh clones.<br>
On one of my OptiPlex 5060 servers, the network adapter would reset on git ssh clones.<br>
This would appear in <code>/var/log/syslog</code> as:
This would appear in <code>/var/log/syslog</code> as:
<pre>
<pre>
Line 820: Line 833:
</syntaxhighlight>
</syntaxhighlight>
}}
}}
==Cloning to a new disk==
The easiest way is to use gparted.
{{hidden | Terminal Guide |
To do this in the terminal:
<syntaxhighlight lang="bash">
OLD_DRIVE=/dev/sda
NEW_DRIVE=/dev/sdb
# Show old drive partitions in sectors
parted $OLD_DRIVE unit s print free
# Apply GPT
parted $NEW_DRIVE mklabel gpt
# Copy new EFI partition with start 1024s and end 1050623s
parted $NEW_DRIVE mkpart primary fat32 2048s 1050623s
# Apply boot and esp flags.
parted $NEW_DRIVE set 1 boot on
parted $NEW_DRIVE set 1 esp on
parted $NEW_DRIVE name 1 'EFI System Partition'
# dd the old to the new
dd if=${OLD_DRIVE}1 of=${NEW_DRIVE}1 bs=4k
# Make a new partition. Make sure start and end sectors are aligned.
# i.e. start % 8 == 0 and end % 8 == 7 if your physical sector size is 4096 bytes, typical for new HDDs and SSDs.
parted $NEW_DRIVE mkpart primary btrfs 1050624s 488396791s
parted $NEW_DRIVE align-check opt 2
# Copy the filesystem
mkfs.btrfs ${NEW_DRIVE}2
mkdir /media/${NEW_DRIVE}
mount -t btrfs -o compress=zstd /media/${NEW_DRIVE}2
rsync -axHAWXS --numeric-ids --info=progress2 /media/${NEW_DRIVE}2
</syntaxhighlight>
[https://superuser.com/questions/307541/copy-entire-file-system-hierarchy-from-one-drive-to-another rsync reference]
;rsync options
* -a    archive mode
* -x    one file system
* -H    preserve hard links
* -A    preserve ACLs
* -W    copy whole files instead of deltas
* -X    preserve extended attributes
* -S    handle sparse files efficiently
* --numeric-ids    use id instead of uid/gid
To copy a root partition, make sure you change the following on the new drive:
* Update the UUID and mount options in <code>/etc/fstab</code>
* Update the UUID in <code>/boot/grub/grub.cfg</code> and run <code>update-grub</code>
* Update the UUID in <code>/boot/EFI/ubuntu/grub.cfg</code>
* Run [https://help.ubuntu.com/community/Boot-Repair boot-repair] from a live disk if you run into any issues.
}}
==Ubuntu==
Ubuntu-specific notes
===Disable ESM message===
[https://askubuntu.com/questions/1453749/inhibit-esm-messages-at-login Reference]
<syntaxhighlight lang="bash">
# Disable MOTD
sudo chmod -x /etc/update-motd.d/88-esm-announce
sudo chmod -x /etc/update-motd.d/91-contract-ua-esm-status
# Disable APT check
sudo sed -Ezi.orig \
  -e 's/(def _output_esm_service_status.outstream, have_esm_service, service_type.:\n)/\1    return\n/' \
  -e 's/(def _output_esm_package_alert.*?\n.*?\n.:\n)/\1    return\n/' \
  /usr/lib/update-notifier/apt_check.py
sudo /usr/lib/update-notifier/update-motd-updates-available --force
</syntaxhighlight>