Ubuntu/Quick Reference
Enable Remote Desktop via VNC (12.04+ - these are just default, you may want to configure more)
- Dash Home > [type] Desktop > [Select] either Desktop Sharing or Remote Desktop
- [check] Allow view and control > [check] require user to enter password > [type] password
Upgrade from 10.04LTS to 12.04LTS via terminal
$ sudo apt-get update $ sudo apt-get install update-manager-core $ sudo vi /etc/update-manager/release-upgrades
- verify there is the following line in the file
prompt=lts
$ sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y autoremove $ sudo do-release-upgrade -d
rename directory with contents
~$ sudo mv -f /path/oldfolderanem /path/newfoldername
ubuntu 14.04 apt-get error
W: GPG error: http://archive.ubuntu.com trusty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
Keys are:
40976EAF437D05B5 3B4FE6ACC0B21F32
fix by importing keys from Canonical's key library:
~$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 ~$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
ubuntu 14.04 locale error
error
perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C").
solution
1. check what locales you have available on the machine
~$ locale -a locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_COLLATE to default locale: No such file or directory C C.UTF-8 POSIX
2. if you're missing the locale for your area like i was, you can sometimes discover the name
~$ locale locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
3. once you know which locale you need, you can build it
~$ sudo locale-gen en_US.UTF-8 Generating locales... en_US.UTF-8... done Generation complete.
4. make sure it's up to date (which is should be)
~$ sudo dpkg-reconfigure locales Generating locales... en_US.UTF-8... up-to-date Generation complete.
5. check to see if the new locale is listed and verify you no longer get the error
~$ locale -a C C.UTF-8 en_US.utf8 POSIX
You'll see here that unlike in step 1, you get the required responses without an error message.
search for directories recursively and add execute permission
~$ find /var/www/mysite.com/ -type d -exec chmod+x {} \;
port scan from behind a firewall to determine which ports are open
first, there are a couple of things you'll need:
- linux box inside the firewall with nmap installed
- linux box outside the firewall with tcpdump installed
essentially, we are going to use nmap to port scan the box outside the firewall from inside, then look at the tcpdump logs and determine which packets got there and what ports they were destined for.
setup tcpdump
setup tcpdump to capture the traffic on the outside box
~$ tcpdump -i <interface> -n <source> i.e. ~$ sudo tcpdump -i venet0:0 -n "src host 8.8.8.8 and not (dst port 80 or dst port 443)" -w port_scan.cap
In my example above, i went 1 extra step and said not to capture any packets going to port 80 or 443. I did this because I saw my firewall had a nifty little feature where it redirected traffic for restricted ports to 80 and 443, so because I already knew these were open, I could determine that any traffic hitting these ports was from redirected blocked ports.
scan with nmap
use nmap from the inside box
~$ nmap -p 1-65535 8.8.8.8
Simple nmap scan of all ports from 1 to 65535 (which are all available ports). The wildcard scan "*" didnt work as well as this did and i got a few more results.
parse the pcap
Once your nmap is done, now we can go back to our box on the outside, stop the tcpdump and start parsing it.
- convert to txt
- first lets convert the pcap to txt
~$ tcpdump -n -r portscan.cap > port_scan.txt
- look at the txt
- really quickly, this is an example of the txt output from our pcap
03:43:59.008245 IP 4.2.2.2.53008 > 8.8.8.8.10443: Flags [S], seq 1225698019, win 14600, options [mss 1380,sackOK,TS val 153049091 ecr 0,nop,wscale 7], length 0
- parse the txt
- now lets extract just the port numbers we care about
~$awk '{print $5;}' port_scan.txt | sed 's/8.8.8.8.//g' | sed 's/://g'
To break down the example above:
- awk uses whitespaces as delimiters by default, so its easy to see the 2nd IP listed with the port is the 5th object.
- the first sed then looks for the outside box's IP, and replaces it with nothing (deleting it)
- the second sed cleans it up by replacing the colon after the port with nothing (deleting it)
results
So in the end, you end up with a nice list of open ports, like such:
~$ awk '{print $5;}' port_scan.txt | sed 's/8.8.8.8.//g' | sed 's/://g' 22 8080 22 22 8173 8173 43 43 5050 5050 15210 15210 1003 1003 8082 10443 10443
Spoof MAC address and connect to network without rebooting
Took me awhile to figure out what series of events would allow me to spoof a MAC address, obtain a new DHCP lease and IP address, and connect to the network without rebooting. Turns out it was super simple.
If ifdown
doesn't work and says something about interface eth0 not configured
, try rebooting. Even a fresh install of 14.04 encountered this issue.
- turn down interface
~$ sudo ifdown eth0
- spoof MAC
~$ sudo ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
- turn up interface
~$ sudo ifup eth0
From here if you run ifconfig
you should see your interface with the new MAC address and DHCP lease with IP address.
find network settings of local interface
~$ nm-tool NetworkManager Tool State: connected (global) - Device: eth1 [Wired connection 2] ------------------------------------------- Type: Wired Driver: r8169 State: connected Default: yes HW Address: 00:11:22:33:44:55 Capabilities: Carrier Detect: yes Speed: 1000 Mb/s Wired Properties Carrier: on IPv4 Settings: Address: 10.0.0.241 Prefix: 24 (255.255.255.0) Gateway: 10.0.0.3 DNS: 10.0.0.3 DNS: 127.0.0.1
Ubuntu Desktop 14.04 - unable to resolve hostnames except through dig
Weird issue, after setting up a local Zentyal server with DNS enabled, I could look up the DNS records I created by using dig, but any other commands, like ping, would not resolve the hostname. Neither would any browsers.
I found out that my /etc/nsswitch.conf
file had this setup for hosts:
hosts: files mdns4_minimal [NOTFOUND=return] dns
So I changed it to this:
hosts: dns files wins
Rebooted and now everything works.
Expand root disk on VM
In this scenario, I needed to expand the disk on a non-LVM ubuntu installation. Nothing particularly special about this setup thankfully, just has the default partition configuration:
~$ sudo fdisk -l .... Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 75497471 75495424 36G 83 Linux /dev/sda2 75499518 83884031 8384514 4G 5 Extended /dev/sda5 75499520 83884031 8384512 4G 82 Linux swap / Solaris
Expand disk in hypervisor
To start things off, we need to expand the disk in the hypervisor. In my case I was using SCVMM atop Hyper-V, so I just powered off the virtual machine > VM properties > hardware configuration > Disk > Expand virtual disk.
Your hypervisor may be different.
Confirm the disk has been expanded (but filesystem has not been). Notice in this example /dev/sda
is 100GB.
~$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 100G 0 disk ├─sda1 8:1 0 38G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sr0 11:0 1 1024M 0 rom
Disable swap and remove partitions
With the root partition starting from the beginning of the disk, in order to expand it the swap partition has to be deleted and recreated. Thankfully since the swap should not be mounted, this is pretty easy.
~$ sudo swapoff -a ~$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 100G 0 disk ├─sda1 8:1 0 38G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 2G 0 part sr0 11:0 1 1024M 0 rom
Before we can delete the swap partition(s), we need to discover the disk name and the partition number(s)
~$ sudo parted -l Model: Msft Virtual Disk (scsi) Disk /dev/sda: 107GB Sector size (logical/physical): 512B/4096B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 40.8GB 40.8GB primary ext4 boot 2 40.8GB 42.9GB 2145MB extended 5 40.8GB 42.9GB 2145MB logical linux-swap(v1)
Now we can delete the swap(s).
~$ sudo parted /dev/sda rm 2 Information: You may need to update /etc/fstab.
Since the logical is within the extended partition, when you remove it, it removes both.
If you needed to check for mounts on the partition, you could use mount
~$ sudo mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,relatime,size=1000664k,nr_inodes=250166,mode=755) ...
Extend root partition
WARNING: the following section is HACKY to say the least. Unfortunately i dont know a better way of doing it yet.
First, we need to create a partition at the end of the drive which will eventually become our new swap space. I'm going to create it using parted
as it will easily let me correctly position the partition.
NOTE: parted
will only create a Win95 Extended partition, not just an Extended. I'm not sure if it matters or not but I will later recreate this partition using fdisk
.
~$ sudo parted -s -a optimal /dev/sda unit GiB mkpart Extended 98GiB 100% ~$ fdisk -l ... Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 79691775 79689728 38G 83 Linux /dev/sda2 205520896 209715199 4194304 2G f W95 Ext'd (LBA)
With the partition in place we can now extend the root, which we can do with growpart
.
~$ sudo apt install -y cloud-guest-utils ~$ sudo growpart /dev/sda 1 CHANGED: partition=1 start=2048 old: size=79689728 end=79691776 new: size=205518848,end=205520896
And we next need to expand the filesystem on the root partition.
~$ sudo resize2fs /dev/sda1
Create new swap partitions
With the root partition extedned, we need to recreate our swap partition(s). We are going to setup a new Extended partition at the new end of the disk. I've chosen 2GB as my RAM is set to 2GB. We are using fdisk
as I do not know of another way to create an Extended partition that is not a "Win95 Extended" partition.
~$ sudo parted /dev/sda rm 2 ~$ ~$ sudo fdisk /dev/sda Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): e Partition number (2-4, default 2): 2 First sector (205520896-209715199, default 205520896): Last sector, +sectors or +size{K,M,G,T,P} (205520896-209715199, default 209715199): Created a new partition 2 of type 'Extended' and of size 2 GiB. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Re-reading the partition table failed.: Device or resource busy The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
Check your work:
sudo fdisk -l ... Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 205520895 205518848 98G 83 Linux /dev/sda2 205520896 209715199 4194304 2G 5 Extended
Finally we want to create a logical drive on top our extended partition. Using the sector start we get from fdisk -l
we need to add (+1) sector to the start positioning.
~$ sudo parted -s -a optimal /dev/sda unit s mkpart logical linux-swap 205520897 100%
This will result in the logical swap partition we want.
~$ sudo fdisk -l Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 205520895 205518848 98G 83 Linux /dev/sda2 205520896 209715199 4194304 2G 5 Extended /dev/sda5 205520897 209715199 4194303 2G 82 Linux swap / Solaris
Create filesystem and enable swap
Now let's create the filesystem on our new swap.
~$ sudo mkswap /dev/sda5 mkswap: warning: /dev/sda5 is misaligned Setting up swapspace version 1, size = 2 GiB (2147475456 bytes) no label, UUID=c9462e3f-f306-484e-b8b4-cf4a680fab87 ~$ sudo swapon /dev/sda5
Now using our new UUID we can update fstab
so that the new swap is used on boot.
~$ sudo vim /etc/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=f0591345-e04f-4a4a-a8b9-41c96e32fc99 / ext4 errors=remount-ro 0 1 # swap was on /dev/sda5 during installation UUID=c9462e3f-f306-484e-b8b4-cf4a680fab87 none swap sw 0 0 /dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
Moment of truth. Reboot.
Check your work
~$ sudo swapon --show NAME TYPE SIZE USED PRIO /dev/sda5 partition 2G 0B -1 ~$ sudo free -m total used free shared buff/cache available Mem: 1991 85 1586 3 320 1856 Swap: 2047 0 2047 ~$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 100G 0 disk ├─sda1 8:1 0 98G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sr0 11:0 1 1024M 0 rom ~$ sudo df -Th Filesystem Type Size Used Avail Use% Mounted on udev devtmpfs 977M 0 977M 0% /dev tmpfs tmpfs 200M 3.2M 197M 2% /run /dev/sda1 ext4 97G 1.8G 91G 2% / tmpfs tmpfs 996M 0 996M 0% /dev/shm tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs tmpfs 996M 0 996M 0% /sys/fs/cgroup tmpfs tmpfs 100K 0 100K 0% /run/lxcfs/controllers tmpfs tmpfs 200M 0 200M 0% /run/user/1000
Targus Dock crashing fix
On Ubuntu 20.04, the targus 190 USZ dock would repeatedly crash a few times a day, sometimes causing the dock to freeze entirely, most of the time just causing the screens to blink on/off and my audio switching back to default speakers.
I found that by disabling the pulse audio idle autooff feature greatly decreased the crashes (none thus far).
Comment out the line below
~$ vim /etc/pulse/default.pa ... ### Automatically suspend sinks/sources that become idle for too long load-module module-suspend-on-idle
systemd resolved not resolving local dns names
update resolvd conf
~$ vim /etc/systemd/resolved.conf ... [Resolve] DNS=10.0.160.1 FallbackDNS=10.0.161.1 Domains=local
restart service
~$ systemctl restart systemd-resolved.service