Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux [2019/02/15 21:06]
paul [Install]
linux [2019/12/28 23:23] (current)
Line 1: Line 1:
 +====== Linux ======
 +
 +Linux is a beautiful example of clean engineering. Form follows function and
 +function follows coherent thoughts. The following is a collection of notes.
 +
 +===== Adding passwordless users =====
 +
 +To add a sudo user that doesn't have a password you have to first add a user with a password, and then delete the password. This activates the password.
 +
 +<code bash>
 +sudo adduser usernameyoulike
 +# give the user any temp password
 +# the following command removes the password
 +sudo passwd -d usernameyoulike
 +# add the user to the sudoers list
 +usermod -aG sudo usernameyoulike
 +</code>
 +
 +===== udev =====
 +
 +I fell in a deep rabbit hole with ''%%udev%%'' whilst building Primo. Here is a
 +comprehensive guide about ''%%udev%%'' [[http://www.reactivated.net/writing_udev_rules.html|link]].
 +
 +To get all the information about a USB device: 
 +
 +<code bash>
 +udevadm info -a -p $(udevadm info -q path -n /dev/video1)
 +</code>
 +
 +Some commands have changed since the bible has been written.
 +
 +To test, you can use the test function of ''%%udevadm%%''. Problem is that you have to give
 +it the top level device path in ''%%sysfs%%''. For example, an arduino plugged into
 +Primo and showing up as ''%%ttyACM1%%'', this was
 +''%%/sys/bus/usb/devices/1-6%%''. To find the top level device path, use the
 +command above and substitute in the port name.
 +
 +To test an Arduino:
 +<code bash>
 +udevadm test /sys/bus/usb/devices/1-6
 +</code>
 +
 +To restart the ''%%udev%%'' system:
 +<code bash>
 +sudo udevadm control --reload-rules && udevadm trigger
 +</code>
 +
 +You will still need to unplug/replug stuff!! Or do a reboot. 
 +
 +Some pitfalls I came across. You cannot change device names! You can only add
 +symlinks to them. The symlink did not work for the Tara uvc_camera. I think this is
 +issue has to do with the fact that the Tara has some weird shit with the way the
 +USB host onboard handles the two cameras.
 +
 +Here's some other commands:
 +
 +Lists the possible device attribute keys and their values along with the
 +parents of the device.
 +
 +<code bash>
 +udevadm info --attribute-walk /dev/bus/usb/<bus_num>/<device_num>
 +</code>
 +
 +Lists the device attributes and their values.
 +<code bash>
 +udevadm info -a /dev/video0
 +</code>
 +
 +Reload udev rules
 +<code bash>
 +udevadm control --reload-rules && udevadm trigger
 +</code>
 +
 +==== USB Information ====
 +
 +To get info on ''%%hidraw%%'' devices:
 +
 +<code bash>
 +cat /sys/class/hidraw/hidraw2/device/uevent
 +</code>
 +
 +<code> 
 +# Arduino with Encoder code
 +# For some readon the serial thingy doesn't work
 +# SSUBSYSTEMS=="usb", ATTRS{iSerial}=="5563930383435181B021", ATTRS{idVendor}=="2a03", ATTRS{idProduct}=="0043", SYMLINK+="ard-enc
 +# SUBSYSTEMS=="usb", ATTRS{idVendor}=="2a03", ATTRS{idProduct}=="0043", ATTRS{idSerial}=="Arduino_Srl_Arduino_Uno_5563930383435181B021", SYMLINK+="ard-enc"
 +
 +SUBSYSTEMS=="usb", ATTRS{idVendor}=="2a03", ATTRS{idProduct}=="0043", SYMLINK+="ard_enc", MODE="0666"
 +# Add a symlink to the stereo camera. This doesn't work with seecam's driver and you
 +# need to reference the device ID.
 +</code>
 +
 +When doing ''%%lsusb%%'', use ''%%sudo%%''!! If you don't, you won't be able to see devices whose
 +permissions haven't been properly set.
 +
 +Shows the USB version of the devices with that vendor id:
 +<code bash>
 +sudo lsusb -v | grep 2560 -A 10 | grep bcdUSB
 +</code>
 +
 +===== cron =====
 +
 +Cron is used to automate the running of jobs. 
 +
 +I use it to run a backup script and a VimWiki html generate script. 
 +
 +To add a job to cron you must edit the crontab file. You do this by running the
 +following command:
 +
 +<code bash>
 +crontab -e
 +</code>
 +
 +This will load up the default editor (you can change this to be vim by running export
 +EDITOR=vim) and open the crontab file. 
 +
 +Cron has an interesting way of setting up timing intervals, look this up online.
 +Here's some examples:
 +
 +<code bash>
 +# Run every minute
 +*\1 * * * * ~/paul_scripts/update_wiki_html.sh
 +
 +# Run on the 45th minute of every hour
 +45 * * * * ~/paul_scripts/cronjob.sh
 +</code>
 +
 +To check the cron logs, type the following:
 +
 +<code bash>
 +grep CRON /var/log/syslog
 +</code>
 +
 +This will show you what jobs where run last. Cron discards the output of these jobs
 +if no MTA is setup, and don't worry about this. 
 +
 +===== Display Manager =====
 +
 +I use the XFCE display manager because it was the only one that allowed my
 +laptop dock and 2 external monitor system to work properly. 
 +
 +==== Workspaces ====
 +
 +Set the number of rows in the workspace to 2. That way you get a nice grid.
 +
 +==== Terminal ====
 +
 +I use the ''%%xfce4-terminal%%''. I have all nicely setup with a config file
 +that resides in ''%%~/.config/xfce4/terminal%%''.
 +
 +===== Moving Windows =====
 +
 +To move windows around we need the following packages.
 +
 +<code bash>
 +sudo apt-get install xdotool
 +sudo apt-get install wmctrl
 +</code>
 +
 +Get the move window script from storage.
 +Add following keyboard shortcut application commands:
 +
 +<code>
 +<CTRL><ALT><SUPER><LEFT Arrow> : /home/paul/paul_scripts/move-to-next-monitor -l
 +<CTRL><ALT><SUPER><RIGHT Arrow> : /home/paul/paul_scripts/move-to-next-monitor -r
 +</code>
 +
 +This information was gathered from [[http://unix.stackexchange.com/questions/48456/xfce-send-window-to-other-monitor-on-keystroke|here]].
 +
 ===== Taskwarrior and Timewarrior ===== ===== Taskwarrior and Timewarrior =====
  
 I use taskwarrior and timewarrior as a task keeping daily  I use taskwarrior and timewarrior as a task keeping daily 
  
-==== Install ====+==== Installing ====
  
 Use pre-built debians for both taskmanager and timewarrior. You have to copy a file to get taskwarrior to use timewarrior.  Use pre-built debians for both taskmanager and timewarrior. You have to copy a file to get taskwarrior to use timewarrior. 
Line 11: Line 180:
 </code> </code>
  
 +===== Remote Desktop =====
 +
 +I have tried every remote desktop option I could find. The best solution in
 +terms of ease of use, performance, and reliability has been TeamViewer. In any
 +case here's a bunch of notes of ones I've tried.
 +
 +==== VNC Notes ====
 +
 +Using default VNC server on Linux machine. Using xvnc4viewer (RealVNC viewer) on
 +xubuntu (xfce) desktop.
 +
 +using the x11 VNC server on the server. Port 5900 and 5901.
 +
 +Running into security issues with the VNC server stuff. Tried:
 +
 +VNC-Server:
 +  * x11vnc with ssl
 +  * tightvncserver 
 +
 +Viewer:
 +  * realvnc viewer (vncviewer)
 +  * xtightvncviewer
 +  * remmina VNC viewer
 +
 +I keep getting "Server did not offer supported security type".
 +
 +Trying out the RealVNC server and viewer. Installing RealVNC on Primo using wget and a
 +Debian pkg. Gave up on installing RealVNC because you need the premium version for
 +headless operation which is what I have. 
 +
 +The server that worked was this: 
 +
 +<code bash>
 +sudo x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth
 +/var/run/lightdm/root/:0 -usepw
 +</code>
 +
 +Issue is getting the x11vnc server to load before a login has occurred, which is what
 +makes all this VNC shit complicated.
 +
 +I used vncviewer on the client computer to talk to it. 
 +
 +Problem is that it is slow. I don't think there is anything we can do it. It is also
 +slow through the LAN. I've attributed this issue to running headless.
 +
 +===== Headless Operation =====
 +
 +I ran into a bunch of issues by running the Primo computer headless, meaning without a
 +display attached to it. The first time I noticed this was when I ran the computer
 +without a display attached to it. It would run extremely slow when trying to remote
 + into it. I then would plug in a display and bam, everything would run nice
 +and fast. 
 +
 +The reason for this is because without a display attached, the onboard GPU does not
 +properly initialize. Everything relating to graphics becomes slow when running
 +headless. X forwarding is slow, steaming video is slow, remote desktop with team
 +viewer and VNC, and any remote video stuff.
 +
 +To diagnose the problem we see what drivers are being used for the graphics
 +operation.
 +
 +<code bash>
 +glxinfo|egrep "OpenGL vendor|OpenGL renderer*"
 +</code>
 +
 +If no hardware acceleration is detected, such when using a non professional grade
 +display, a virtual driver such as this one will be detected:
 +
 +<code>
 +OpenGL vendor string: VMware, Inc.
 +OpenGL renderer string: Gallium 0.4 on llvmpipe (LLVM 3.8, 256 bits)
 +</code>
 +
 +To solve this problem I found the following solutions:
 +
 +==== Dummy Plug ====
 +
 +There are cheap dummy plugs that trick the video card into thinking that there
 +is a display attached.
 +The[[https://www.kickstarter.com/projects/devjoshi/headless-ghost|Headless
 +Ghost]] is one of them. I bought the
 +[[https://www.amazon.com/gp/product/B06XT1Z9TF/ref=oh_aui_search_asin_title?ie=UTF8&psc=1|cheap
 +knockoff from Amazon]] which worked great.
 +
 +==== Use a Display ====
 +
 +The other obvious solution is to use a display. I purchased an
 +[[http://amzn.to/2sQ8fEy|800x480 TFT LCD screen with a touch screen designed for
 +the Raspberry Pi for 40 bucks]].
 +
 +===== CLI Shortcuts =====
 +
 +Here are some command line shortcuts.
 +  * $_ gives the argument of the last command
 +  * . (dot command) same as source. This executes a list of commands. That is all.
 +  * use ssh -X if you want to ssh with an X server
 +
 +To remove all files except for one in ''%%zsh%%'':
 +
 +<code bash>
 +setopt extendedglob
 +rm -- ^file.txt
 +</code>
 +
 +==== Clipboard =====
 +
 +To pump out contents of file to clipboard:
 +<code bash>
 +sudo apt install xclip
 +cat file | xclip -selection clipboard
 +</code>
 +
 +
 +====== Window File Subsystem for Linux ======
 +
 +This thing is awesome! 
 +
 +For setting up ssh keys, xclip doesn't work. Use the following:
 +<code bash>
 +clip.exe < ~/.ssh/id_rsa.pub
 +</code>
 +
 +===== SSH Access =====
 +
 +For setting up external ssh access I did the following:
 +
 +Reinstall openssh for some reason:
 +<code bash>
 +sudo apt-get purge openssh-server
 +sudo apt-get install openssh-server
 +</code>
 +
 +From an elevated powershell I ran this to change the port to 2222 to not
 +interfere with any windows services:
 +<code bash>
 +New-NetFirewallRule -DisplayName "Allow Inbound Port 2222" -Direction Inbound -LocalPort 2222 -Protocol TCP -Action Allow
 +</code>
 +
 +I added the following to sshd_config:
 +
 +<code bash>
 +Port 2222
 +PermitRootLogin no
 +AllowUsers paul
 +</code>
 +
 +I created an authorized hosts file and imported the keys.
 +
 +I tested the connection by running this on the server:
 +<code bash>
 +sudo service ssh stop
 +sudo /usr/sbin/sshd -d
 +</code>
 +
 +Then on the client I ran a debug version of an ssh server to see if I was
 +receiving incoming connections.
 +<code bash>
 +ssh name@server -p 2222
 +</code>
 +
 +I then monitored the server and make sure I could see the connection. The debug
 +client quit out cause it didn't have correct paths to the keys, but the test was
 +a success cause it validated the port pass through. I then restarted the regular
 +service like this:
 +
 +<code bash>
 +sudo service ssh start
 +</code>
  
  • linux.1550264806.txt.gz
  • Last modified: 2019/02/15 21:06
  • by paul