Tuesday, January 22, 2019

SSH private keys with passwords

Setting up OpenSSH keys, to avoid having to type a password when logging in to remote systems, is pretty straight forward.  In brief:

Generate public and private keys (just hit enter when prompted for a password):
  ssh-keygen -t rsa

Then copy the keys to the hosts you want to be able to log in to:
  ssh-copy-id hostname

You can pass the -b option to ssh-keygen and specify the number of bits you want to use.  The default is 2048.  (A lot of articles I've read go with 4096 bits.  But then I've also read it doesn't make a whole lot of difference, as RSA is basically secure for the foreseeable future.)

And as an aside, I've actually started going with the -t ed25519 option, which is a newer algorithm.  It's not supported everywhere though, so creating fallback RSA keys might be a good idea still.

Also, instead of using ssh-copy-id, you could of course manually edit the ~/.ssh/authorized keys files on remote systems.  This is what I used to naively do in fact, but I see no reason not to use the ssh-copy-id command at this point.

If you do password protect your private key, when you attempt to log in to a remote machine, the difference will be that rather than typing in your password on the remote system, you will need to type a password to decrypt your private key.  For me, this sorta defeats the purpose since I like not having to type a password (I do realize ssh keys are better from a security standpoint).  So enter ssh-agent and ssh-add.  With these programs you'll only need to type a password once per session.

Assuming you use bash:
  eval $(ssh-agent)
  ssh-add ~/.ssh/id_rsa

Even better though, from my viewpoint, is the keychain program. With keychain you should only have to type your password once in between boots. Keychain will start ssh-agent if it's not already running, or connect to a running instance of ssh-agent if it is running as well as add any keys you specify.

In short, I've added this to my bash login scripts:
  eval $(/usr/bin/keychain --eval /home/glen/.ssh/id_rsa)

So now, when it comes to SSH keys with passwords I'm a happy campers.

And like always, this blog is mainly for writing practice and personal reference, but if anyone happens to get some use out of it, cheers.

Wednesday, October 5, 2016

Windows Server 2016 Updates

I installed a demo version of Windows Server 2016 over the weekend, and I was going through my usual drill of setting things up.  I believe I was in the midst of installing Anaconda, a Python distribution for Windows, when I decided to grab a snack.  Perhaps 5 minutes later I come back, and "uh-oh...what's this?  30%, don't turn off my computer???"  Windows had decided to reboot all on its own to apply updates.  Right in the middle of a software installation I was performing.

Apparently Server 2016 is going to be just as moronic by default as Windows 10.  I just can't see how in the world that Microsoft thinks letting a restart happen automatically after updates is a good thing on a server operating system.  A bit of research and sure, it all seems tweakable, but in a very non-sane way.  Some options are in the settings menu, some options you can tweak via group policy, other options you need to download a tool from Microsoft.  Can the options not all be in one place?  Argh!  Can they at least have some sane defaults???

Or maybe I'm missing something regarding updates making them intuitive and easy to deal with, but it sure doesn't seem so.  At this point it just boggles my mind how much of a nightmare it all is.

And yes, I am aware of WSUS, but that sure seems like overkill for a standalone server such as the one I'm currently experimenting with.

Wednesday, September 7, 2016

Gnome's Nautilus

I mostly stick to a Bash shell for my workflow.  I just find things to be faster that way.  Ha, or it gives me the illusion of faster at the very least?  Anyhow, every once in a while I do find myself using a GUI file manager.  Viewing images would be one great example, as skimming through a bunch of thumbnails vs. any alternative method definitely makes the most sense.

Now given that I mostly run Fedora Linux and that I have a tendency to go with the default of Gnome for my desktop environment, if I'm using a file manager it's going to be Nautilus.  And most of the time Nautilus suits me just fine.  It has a nice simple interface that at the same time is smartly designed enough to allow me to quickly navigate and manipulate my files.

There are two problems I have with Nautilus.  First, they got rid of the delete option on the context menu.  Or maybe there's some dconf voodoo I could perform to get it back, but that road is madness.  I live with shift-delete for now.

The second problem for me, there are no options on the context menu anymore to create new files.  At least by default.  Or maybe my memory is fuzzy after 24 releases of Fedora and the options were never there.  Right.  The workaround is to populate the 'Templates' directory in your home directory.

Any file you put into Templates will show up Nautilus's 'New Document' menu, which is a submenu of the context menu.  And when you create a new file using this menu, anything contained in a Templates file will be copied over to your new file.

So for example, if you want to be able to create a new empty text file, simply put an empty file in Templates and name it 'Text Document.txt'.  Want a new Python script option?  Put a file in Templates called 'Python Script.py' with a shebang up top.  Now when you create a new python script the shebang will be at the top of your new script.  Anything that's in a template file gets copied over to the new file.

A few things to note about template files.  Binary files are certainly an option here.  Also, file extensions won't show up in the 'New Document' menu, but will show up in your newly created file's name.  And if a file of the same name as the one you're trying to create exists already, don't worry, a number, starting at 2, will be appended to the new file's name.

Yep, Nautilus is a great application with only a few tiny warts from my perspective.  And now I won't forget about templates ever again, ha, the whole reason I started this post.  Cheers.

Saturday, August 6, 2016

Notes on Git

Git is a distributed version control system developed by Linus Torvalds. It's basically the weapon of choice when it comes to version control these days.  So after using Subversion for the longest time, I made the jump to Git and haven't looked back.  I do tend to forget things though if I go a while in between uses and/or if OS upgrades have happened in between.  Yikes, it's been a year or so since I've pushed anything to GitHub.  In my defense, I have been and still am relying heavily on Syncthing to handle my data.  Anyhow, as of yesterday, I'm back up to speed with Git for my purposes.

Here's a few things I might find my future self forgetting again.

If I'm a dummy and forgot to save my ssh keys:
ssh-keygen -t rsa -b 4096 -C 'foo@bar.com'
If I want to put a local repository on GitHub, the first step is to create an empty repository on GitHub, and then, at the top level of my local repository, run:
git remote add origin git@github.com:AssumeACanOpener/some_project.git
Be sure to go with ssh and not https, unless you like typing usernames and passwords all the time.

On your initial push to GitHub do:
 git push -u origin master
Otherwise a pull is going to say you're not up to date, even though you are really.

In the past when I accidentally tracked files, I'd imagine I've probably just copied something, did a git rm, and then moved whatever it was back.  But there's a better way.  If you've accidentally added a file to version control, but you don't want to delete it and simply take it out of version control:
 git rm --cached file.txt
Put file names you don't want to track into a .gitignore file at the top level of your repository.  Funnily enough, you need to add .gitignore to the .gitignore file.

To check what files are currently under version control:
git ls-tree -r master --name-only
If you've forked something from github and still want to follow upstream changes, you'll need to add the upstream repository to your fork.  For example:
git remote add upstream https://github.com/gregmalcolm/python_koans.git
Then, to update:
git pull upstream master
And if I ever forget the init, add, status, and commit commands, I need to pack it up and go home.

Wednesday, July 6, 2016

Fedora 24 and Nouveau drivers

My laptop uses Nvidia Optimus for video.  This means the GPU built in to the CPU is for for 2D, and the Nvidia adapter is used for 3D.  The idea I'm assuming is to save power.  Great, who doesn't want their laptop battery to last longer?

In Linux land though, Optimus is problematic.  The proprietary Nvidia drivers don't support it (licensing issues are getting in the way unfortunately).  Given that's the case, I've been sticking to Nouveau, the open source driver for Nvidia cards that comes stock with Fedora.  I haven't been able to play any 3d games on my laptop because of this, but do I have a Windows machine sitting around somewheres if I really need to scratch that itch.

Fedora 24 and Nouveau drivers turned out to be a whole different ball game however.  After installing F24, I noticed my laptop was running really really hot.  Lm sensors, a hardware monitoring tool for Linux, told me my idle CPUs were sitting at a little under 70 degrees Celsius.  Yikes!  Not good.

Bumblebee to the rescue!  Bumblebee is an open source Linux project that lets you switch between the integrated GPU and the Nvidia adapter.  With Bumblebee, by default graphics are handled by the integrated chip.  You can manually run applications with the "optirun" or the "primusrun" commands though and then graphics will be handled by the more powerful Nvidia chip.  Bumblebee supports the proprietary Nvidia drivers as well, so 3d games are not a problem.

So why have I been sticking with Nouveau?  Well, setting up Bumblebee in the past has been a bit involved and didn't always turn out well.  But it seems some Fedora folks have been busy making it all very simple.  Following this guide I had Bumblebee installed and working in a matter of minutes.  A quick reboot, and my CPU temperatures went down to under 50 degrees Celsius.  So sure, things started out a bit rocky with Optimus, but give it time and the open source community does not disappoint.  Looks like I will not be running Nouveau drivers again any time soon.

Sunday, July 3, 2016

Upgrading Fedora

I recently upgraded my laptop to Fedora 24 and took notes about the process.  I'm collecting them here, mostly for future reference, but also for anybody else out there that maybe happens to stumble upon them.

First things first, before upgrading I make sure to do the following:
  1. Push any git commits that need to be pushed.  This includes dot files if I've changed them (haha, argh! Just got burned by this one actually).
  2. Make sure Syncthing is properly syncing the files I have under its control, and that everything is up to date everywhere.
  3. Go through ~/Applications and see if there's anything I want to save, and if so manually back things up. 
  4. Manually back up my documents and projects.
  5. Manually back up any videos or other large files I happen to want to save
First off, let me say Syncthing is awesome.  Fairly easy to set up and really low maintenance once it's up and running.  I use it to keep all my documents and projects in sync between 3 of my home systems.  If you haven't tried it you should check it out.

Why all the manual backing up of things?  Well, for anything 'important' I mainly rely on Syncthing to distribute things around my network, and then rsnapshot to throw things onto a back up drive.  But it definitely doesn't hurt to have a few extra copies of important stuff lying around.  Everything else?  Well, I'm a digital packrat and there's no way I'd be able to keep everything (not without spending a ton of money anyhow).  I'm keeping enough mooc videos I'll probably never watch as it is.  Upgrades always motivate me (well, make it necessary perhaps) to organize and cull both old and new data, so I do.  I like to think it's a good thing.

I never have trusted the Fedora upgrade process.  I've heard a lot of bad things, so I always perform a fresh install.  Maybe this just means I'm making more work for myself?  Anyhow, post upgrade, I did the following:
  1. Add the following to /etc/dnf/dnf.conf: "fastestmirror=True".
  2. Run "dnf update", and reboot.
  3. Change the desktop and lock screen backgrounds (I may do some of these while updates are running of course), which is in Gnome settings, under background.
  4. Turn off the terminal bell.  Found on the terminal edit menu, under profile preferences.
  5. Disable screen lock.  Found in Gnome settings, under privacy.
  6. Clone my dot files from git and copy them to where they need to be.
  7. dnf install hexchat p7zip vim-enhanced gnome-tweak-tool
  8. Enable Firefox sync.
  9. Configure my Gnome favorites.
  10. Import rpmfusion gpg keys: "gpg --keyserver pgp.mit.edu --recv-keys (ID)".  IDs and more info are found on the site.
  11. Install rpmfusion free and non-free repos.  The "localinstall" option isn't a thing anymore.  Just download the rpms and run "dnf install rpmfusion.foo.rpm".
  12. Install fonts: "dnf install freetype-freeworld".
  13. Install media codecs:  "dnf install gstreamer-plugins-bad gstreamer-plugins-bad-free gstreamer-plugins-bad-nonfree gstreamer-plugins-good-extras gstreamer-plugins-ugly gstreamer1-plugins-bad-free-extras gstreamer1-plugins-ugly gstreamer1-plugins-bad-free-fluidsynth gstreamer1-plugins-bad-freeworld gstreamer1-plugins-base-tools gstreamer1-plugins-entrans gstreamer1-plugins-fc gstreamer1-plugins-good-extras gstreamer-ffmpeg ffmpeg-libs ffmpeg x264 x264-libs h264enc lame lame-libs lame-mp3x twolame mpg123-plugins-extras mpg123 faad2 gstreamer1-libav"
  14. With Gnome Tweak tool enable the global dark theme, enable the date on the top bar, set font antialiasing to "rgba", set font hinting to "none", and set the window focus mode to "mouse".
  15. Add the following to /etc/X11/Xresources: "Xft.lcdfilter: lcddefault".
  16. Install whatever it is I'm working on at the moment, in this case: "dnf install octave qtoctave python2-matplotlib python3-matplotlib python-ipython-notebook python3-ipython-notebook python2-pandas python3-pandas python2-numpy python3-numpy python2-scikit-learn python3-scikit-learn python2-statsmodels python3-statsmodels"
  17. Install and set up Syncthing so I have my projects and data back.
  18. And finally save a list of available packages for future reference, so: dnf list available >& /root/available_packages
One thing I've noticed, I'm not able to play videos half the time if I follow some of the guides you find out there.  So then I always have to sit there installing things until I finally get working videos.  This time around I was determined to figure out what's wrong with the available guides.  So I could be wrong, but it seems to me they're typically missing the gstreamer1-libav package.  Once I installed that I was able to play videos no problem.  Well, maybe Quicktime or Real videos could still be problematic?  Eh, are those even a thing anymore?  At any rate, gstreamer1-libnav and I'm happy.

And that's how it's done on my end.  I'm not saying this is what everyone should do, but it's what I do to get myself back up and running and productive again.  If you're reading this, maybe you'll pick up some tricks?  Or maybe just satisfy a bit of your curiosity.  Cheers.

Saturday, July 2, 2016

Booting Fedora to RAM

So I installed Fedora 24 yesterday.  And while not the only option, the default installation CD is a live CD that boots up a Gnome desktop, and from there gives you the option to either just play around with Fedora or to run the installer application and install Fedora to your hard disk.

As an aside, I chose the Gnome live CD because that will install Gnome.  If another particular environment happens to be your thing, then you'll need to choose the appropriate live CD.  In Fedora land these are called spins, and you can find out more about them here.

And as another aside, while I don't always do it, a lot of times upon a new release of Fedora I'll force myself to switch up from Gnome to something different, until the next Fedora release or until I tire of it.  I suppose KDE might be the only environment I've actually stuck with for a full release cycle besides Gnome (I miss the more polished, integrated, and full featured applications too much I guess), but still, switching it up every now and again helps me not to stagnate I like to think.  Speaking of which, I should probably give xmonad (a tiling window manager) or the like a try for once.  Maybe I will this time around.

Anyhow, given my wealth of ram, it makes sense to me to, if at all possible, load my live CDs into RAM when I boot them.  This is easy to do with Fedora, though not as simple as I'd like it to be, namely it being a menu item.  But still pretty easy.  When presented with the initial live CD menu, hit the 'e' key to edit the menu entry.  Then append the kernel line with 'rd.live.ram'.  Hit ctrl-x to boot and you're set.  It will take a bit longer to boot of course as everything needs to be loaded into ram.

So what's the point?  If you're simply wanting to give a particular desktop a go, loading things into RAM will make everything much more responsive and way closer to to what the true desktop experience would be like.  But even if you're just performing an install, if you're like me you might need to fire up a terminal and do some low level pre-install or post-install tasks.  Or you might just want to bring up a browser or the like while you wait for the installation to finish.  Booting to RAM makes this so much more pleasant.

And a bit of trivia.  Though it wasn't exactly a live CD, older versions of Solaris were the first perhaps, the first install CDs I ever encountered anyway, where you could use a browser while you were waiting for the installer.  Quite neat back in the day.

Wednesday, June 29, 2016

Deep Learning

I'm currently reading a book on deep learning and I have to say, it's quite interesting.  Apparently a lot of the machine learning methodology in use today has been around for a very long time, circa 1950 or so, and in fact some of today's methodologies have even been simplified compared to past models.  Only with the advent of big data is there enough training data available to be able to train some models adequately.

And combine big data with the computational resources available currently, it's no wonder we're seeing a resurgence in AI research.  Exciting times in the world of computer science to be sure.  Now where's my self driving car???

Tuesday, June 3, 2014

Time to learn some Q

Ever since coming across this maddness I've found J and the APL family of languages quite interesting.  To the unfamiliar the beginnings of the J interpreter look to be something akin to an IOCCC entry.  But then how and why would brilliant sounding guys like Ken Iverson and Arthur Whitney be coding like this?  Through a bit of research I've learned that this style can actually make code much simpler to read, almost like a book in fact.  Or that's the claim at least.  I've yet to really make any headway with that fragment, so I myself am not a yet a convert.  Perhaps actually learning an APLish language will help.

I've briefly touched on J off and on over the years but never really buckled down.  This time around I'm switching to one of it's successors, Q.  A free 32 bit version of the interpreter (and kdb+) can be found here.  On Linux, simply extract it to where you want it to reside, set $QHOME to that location, and put $QHOME/l32 in your shell's path.  Run "q" and you're good to go.  If your machine is running a 64 bit OS you will need 32 bit compatibility libraries however.

I've already started in on this tutorial.  So far so good.

Tracking progress through old code

It feels good to have a look at some older code you've written and see that you've most definitely improved.  I'd urge everyone to try it.

I've recently been learning more Ruby by doing problems on Code Abbey.  The very first problems involve summing integers that are passed in via standard input.  My original solution turned out to be as follows:

numbers = []
numberStrings = gets.chomp.split
numberStrings.each {|number| numbers << number.to_i}
sum = 0
numbers.each {|number| sum = sum + number}
print "#{sum.to_s}\n"

And this is fine, in that it works. But were I to code this today it would simply read like this:

puts readline.chomp.split.map(&:to_i).reduce(:+).to_s

Of course it's the exact same thing conceptually, but Ruby-wise, it's a vast improvement.

So, have a look at some of your own code my friends. You may be pleasantly surprised at the progress you've made.

Tuesday, September 18, 2012

Online courses

There's been quite a number of free online courses popping up recently, with the 3 major players being CourseraUdacity, and edX.  The amount and quality of content is really exciting.  Not only am I personally able to take advantage of these programs but so are people all across the world, many of whom wouldn't otherwise have access to a university education.

Of the three, Udacity is definitely the most accessible.  Not only does it have very entry level courses, but the lectures are split up in to very manageable chunks.  On top of that the courses are self paced so there are no deadlines to worry about.  And while all 3 platforms do it, Udacity really seems to shine in how it intersperses quizzes and exercises with the lectures. It keeps you very engaged with the courses.  Almost all of Udacity courses are computer science courses however, so if computer science isn't what you're after then you're mostly out of luck.

Coursera material, from math to history, to art, varies widely. On the computer science end material seems a bit more rigorous and advanced than Udacity.  This combined with the fact that courses are on a deadline makes things feel closer to an actual university.  However one problem with Coursera, in my opinion, is the quality and quantity of what I guess could be called the homework.  A lot of it seems far too simplistic and there isn't enough of it to really drive home the material.  The programming projects though are not nearly so trivial so perhaps it all evens out.

edX, with its Circuits and Electronics course, seems closest of all to an actual university offering.  There are both lectures and recitation videos, a full textbook is available, the homework is very appropriate, and there's even lab work in the form of a circuit simulator.  Like Coursera, edX courses do have deadlines, so depending on your point of view this is one downside.  Still, I have to say I'm very much enjoying their program and am definitely looking forward to edX's upcoming introduction to programming course.  If it's going to be anything like the Abelson Sussman lectures it's going to be spectacular. The downside to edX is that it seems to suffer from a lack of content, but hopefully this will change in the future.

Considering the cost, namely free, all three sites are wonderful additions to the Internet.  It's going to be a lot of fun watching them mature.

Outputting Data in Binary.


C++ doesn't have an easy way to print out an integer in binary, so I ended up rolling my own method today.  I vaguely recall doing this before but I'm fairly certain I targeted a particular data type.  This time around I figured I might as well just use templates so I can handle any data type.

All this just so I could let my brain be lazy and not have to mentally translate hex to binary.  Which of course I was doing to make sure I was feeding proper input to a rather meaningless probability experiment.  I'm not so sure I took the easy way out at this point.

Along the way, the precedence of the bitwise operator & caused me some grief.  It's lower than the == operator so my expressions were unexpectedly evaluating to true.  I learned a bit of history as to why things seem brain damaged.

Anyhow, here's some code:

template <typename T>
void toBinary(T data) {
  unsigned char *currentByte = (unsigned char *) &data;
  unsigned char mask = 0x01;
  std::string byteString;
  std::string output = "";

  currentByte = currentByte + sizeof(T) - 1;

  //loop through each byte of data
  for (int i = sizeof(T); i > 0; i--) {

    //convert each byte to a binary string
    byteString = "";
    for (int j = 0; j < 8; j++) {
      if (*currentByte & mask) {
        byteString = "1" + byteString;
      } else {
        byteString = "0" + byteString;
      }
      *currentByte = *currentByte >> 1;
    }

    output = output + byteString;
    currentByte--;
  }
  std::cout << output << std::endl;
}

Fedora 18.

It's 2am.  I barely managed to squeak in my Coursera homework today.  I'm still getting over my cold or making it worse at this point.  Is there a better time to try out Fedora 18 alpha? Not likely.

Just like the F17 live cd there is no firmware for my wireless nic, which is annoying.  Nautilus, the file manager, is refusing to mount my Windows and Linux partitions which is even more annoying. Still, my wireless problems are easily remedied by manually mounting things and grabbing the firmware off my f17 install.  After reloading the driver for my nic I'm good to go.

Right away this has me salivating for the final f18 release.  I really like some of the UI simplifications and some of the new applications sound quite interesting.   The new installer is just plain beautiful.  Unfortunately the installer isn't quite mature.  I'm unable to do anything but use free space for an install.

Switching to the dvd installation media solves the firmware issue, which is good to know, and existing partitions even show up.  But things still aren't fine grained enough for me to be able to specify which particular disk a partition is going to live on.  Looks as though I'm going to have to wait for the beta at the very least.  Given my inexperience with btrfs I don't exactly trust myself to come up with a sane kickstart file.


Blog Time!

I'm starting a blog apparently.  I should have done this ages ago, but better late than never.

If nothing else this is going to be a great spot to collect for future reference some of the various things I run into on the internet.  But maybe, just maybe, some of the tips and tricks I happen to find, or experiments I run, will come in useful to someone.