Category Archives: Uncategorized

Public Key Cryptography

We talked about how in cryptography you want your key to be complex so people can’t guess it.  Otherwise, why encrypt if they can figure out how to decrypt it easily?  We need another play to fix this. We’re going to talk about that other plan, it’s called Public Key Cryptography.

Public Key Cryptography means I have a public cryptography key.

Public Key

Public Key

I can use that to encrypt anything I want, but I can’t use it to decrypt anything.  It’s like having a key to your house that will only lock doors, but not unlock them.  I can lock the house up when I leave, but there’s no way for me to get back inside.  This means I can share the key because there’s no worry that someone will break in using it.  In Public Key Cryptography, I share my public key with the world and they can encrypt things they want to send me.

Private Key

Private Key

This is my private key, it’s purple because that’s my favorite color and this is my favorite key.  It’s the one I can use to unlock doors, or in encryption terms, I can use it to decrypt anything that’s encrypted with my public key.

This sounds pretty safe, right?  It’s actually used in something called Pretty Good Privacy so we’ll call it Pretty Safe Public Key Cryptography.  Well, not really, the real name doesn’t have Pretty Safe as part of it, but it’s still a good name.

It’s also used in web traffic.  If you go to a website using https:// rather than http://, you’re making a secure connection that encrypts your traffic.  That’s done using Public Key Cryptography, it’s just under the hood so you don’t see it.

Pretty cool, right?

 

cowsay

We’re going to talk about another silly Linux® command because this one is one of my favorites.  It’s not a banner command like figlet or banner, instead, it’s called cowsay.

You read that right.  This post is about a command that’s called cowsay.  How silly is that?  Let’s look at the top of the man page for this command:

cowsay(1)                                                                  cowsay(1)

NAME
       cowsay/cowthink - configurable speaking/thinking cow (and a bit more)

A configurable speaking/thinking cow.  I did promise a silly command!  Let’s try it out:

Alpha:~ computerlamp$ cowsay Hi There!
 ___________
< Hi There! >
 -----------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Yes, that’s a cow saying Hi There!   I did promise a silly command.

I want to do it again, this command is fun!

Alpha:~ computerlamp$ cowsay Commandline is fun!
 _____________________
< Commandline is fun! >
 ---------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

What if I don’t want my cow to speak and I would rather that my cow thinks?  Well, there’s a command for that!  It’s called cowthink.

Alpha:~ computerlamp$ cowthink This is silly!
 ________________
( This is silly! )
 ----------------
        o   ^__^
         o  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Unfortunately, there isn’t a catthink or a catsay.  I think that would be a lot of fun.  Maybe one day someone will write one!

Linux® has a lot of silly commands, as we’ve seen.  Even Linux® users want to have fun with the command line!

 

Computer Memory and Linux®

You have memory where you sit and remember, well, computers have a similar thing.  And it’s also called memory.  Sounds kind of silly to also call it memory, but it actually kind of works.

Computers have two kinds of memory.  There’s hard drives, where it stores programs.  You can think of it like the memories you have.  You can sit there and remember watching Star Wars, right?  A computer can save all of Star Wars to its hard drive so you (or it, if it wants) can watch it again and again.

The other kind of memory is the thinking kind.  If I sit here and think about what Luke Skywalker and Rey have to say each other, that’s not the remembering kind of memory, that’s the thinking kind.  When your computer is running a program, it’s thinking.  When you look at a directory, it’s remembering.

So, how much thinking memory does my computer have?  Of course, there’s a command for that!  It’s called free.

Alpha:~ computerlamp$ free -g
             total       used       free     shared    buffers     cached
Mem:            31         29          1          0          0         12
-/+ buffers/cache:         17         13
Swap:            2          2          0

So when I used the -g flag, I wanted to know the results in gigabytes.  If I don’t use that flag, I get the results in bytes.  That doesn’t really mean much to me, so I’ll go with gigabytes.

The man page for free also tells me to ignore the shared column, that’s obsolete.

But back to the results.  The first column tells me I have 31 Gigabytes of memory on this system and 29 are used but 1 is free.  That’s weird, right?  Its because the system actually counts them in bytes and then divides things out (and rounds it off) for the results.  It wants to give you nice pretty numbers to look at.

The bottom row, that’s called swap and we’ll talk about it in the next post.

Index of ComputerLamp Posts

You will find 83 posts in the category Linux on this blog.


Jump to B, C, D, E, F, H, I, K, L, M, N, P, R, S, T, U, V, W

B (4)

C (4)

D (8)

E (3)

F (6)

H (3)

I (5)

K (3)

L (9)

M (9)

N (2)

P (7)

R (2)

S (8)

T (6)

U (1)

V (1)

W (2)

Permissions or How to Hide Things

I promised in the last post that I’d tell you how to fix that little problem where Hydra can see in the Insight directory, also known as a permissions problem. We call that a big ‘oops’ because we don’t want them to see anything in there.

The Insight directory looked like:

drwxr-xr-x  2 computerlamp  shield  68 Nov 13 09:56 Insight/

Our problem has two parts that we need to fix. First, the group permissions on this directory don’t let the shield group write to it. Secondly, the world (that is, anyone!) can see in the directory. Let’s start with the first problem. We want shield to be able to write in that directory.

The command we’re going to use is called chmod. So I want the group permissions to look like rwx. I can do this:

Alpha:~ computerlamp$ chmod g=rwx Insight

That means change the permissions on Insight for the group to read, write and execute. Check out the results in ls -l:

drwxrwxr-x  2 computerlamp  shield  68 Nov 13 09:56 Insight/

I’m halfway there. I want the last three letters, those things that are currently r-x to be . The chmod command for that looks like:

Alpha:~ computerlamp$ chmod o=--- Insight

We’ve done it! Hydra is prevented from seeing in the Insight directory.  We fixed our permissions problem.

drwxrwx---  2 computerlamp  shield  68 Nov 13 09:56 Insight/

Then we have the horrible moment when S.H.I.E.L.D. fell and we discovered that Hydra was part of S.H.I.E.L.D. all along. This means we need to remove that group access from Project Insight, though it’s probably a little late. But we do what we can, which includes blowing up helicarriers. The command to remove all access from the group is:

Alpha:~ computerlamp$ chmod g=--- Insight

Checking things out with ls -l again, we see:

drwx------  2 computerlamp  shield  68 Nov 13 09:56 Insight/

Which means that only I can read what’s in that directory, write to it, or make anything run.

Find… and Exec

In the last two posts, we talked about finding things. The result of that find command was a list of filenames or directory names… just lists of things. Which is useful if we want to know ‘where did I leave that file’. But I want to do things with these files. Suppose I want to know when all files that have an ‘s’ in them were last accessed. I could do that by finding all of those files and then doing ls -l on each one. But I’m lazy, I don’t want to do that.

As I’ve said many times, there’s more than one way of doing things in Linux. You can do things the long and complicated way or you can learn a little about the command line and do things the short and fast way. Let’s talk about that short and fast way and get to the end result. I’m lazy. I don’t want to type the same thing over and over again. Luckily, find lets me get away from that. See?

find . -name '*s*' -exec ls -l {} \;

So I’m finding all files that have an s in them, just like I’ve done before. Now, though, I’m adding a new flag, -exec. After that flag, I give the command I want. The {} means take the output of the find and put that value in those brackets. So it’s going to do ls -l on every file it finds.

One command to take care of all those commands I listed before, isn’t that neat?

Now let’s pretend I want to rid my system of all sith. Those sith infested my system with lots of files, all of them with the name sith (or some variant thereof) and I’ve got to get rid of them.

find / -iname '*sith*' -exec rm {} \;

So I find any file with the name sith or Sith or DarthSith or SithofDarkness or even sItH… and I remove them. All go away and I don’t even need to find my lightsaber.

I’ve lost my files, how can I find them?

We’ve talked about finding things in files and using grep and more to do that, let’s talk about finding files. I’ve lost my file and I can’t look through my file until I find my file.

And that’s what the command Linux® uses to find files is called. find. How’s that for imaginative naming? We’re going to find with find.

Let’s begin by cd‘ing into our home directory. Remember we can do that just by typing cd.

We want to find that file blog1.txt we created a while back. We know it exists, we know we put it somewhere, but we forget where. (It was in the home directory but let’s pretend otherwise for right now.) We tell find to start in the home directory and look for a file named blog1.txt. This is done by:

Alpha:~ computerlamp$ find . -name blog1.txt

See that ‘.’ after find? That’s really important. That tells find to start in the directory you’re in and look from there. The flag ‘-name’ tells the command ‘look for the file with this name’.

We can do other neat things. Suppose we know the file we’re looking for ends with the letters txt but we’ve forgotten if it started with blog, or blogg, or maybe bloggo, or even MyBlog. But we know it ends with txt, so that’s a start! In this case, we can do this command:

Alpha:~ computerlamp$ find . -name '*txt'

See that asterisk? That tells find to match any file that ends with txt and starts with anything else. It could be blog or bloggo, but it could even be thisfile.txt. Or turtles.txt. Or turtles-in-txt. It can match all of those and find will return every single one.

We can also find directories with find. Remember that Sewer directory we made a while back? find will find that as well:

Alpha:~ computerlamp$ find . -name Sewer

We can also use find to look into the sewer.

Alpha:~ computerlamp$ find Sewer

I didn’t give it a name flag that time. That means it’ll look into that directory and find whatever is in there.

 

Finding words in files… take two!

In the last post we discussed how to find a word in the file /usr/share/dict/words using more.  This being Linux®, there’s always another way to do it.  This way uses the command grep. Jumping right to an example, try this:

Alpha:~ computerlamp$  grep way /usr/share/dict/words

This returns every single word in the file /usr/share/dict/words that contains way.  As in the last post, we’re looking for words that begin with way, not any word that contains way. We can find those words using:

Alpha:~ computerlamp$  grep ^way /usr/share/dict/words

This returns every word that begins with way.  When I tried it, I got 48 words.  How many do you get?

grep is case specific. This means that if you tell it to find way, it won’t find Way or wAy or waY. It matches precisely what you give it. As luck would have it, we don’t have to grep for every possible combination of case. There’s a flag for that. We can use the flag -i to ignore the case. That means, match every possible case when looking for the word way. For example:

Alpha:~ computerlamp$  grep -i ^way /usr/share/dict/words

That finds every possible word that begins with way, no matter what case it has in the file.

How, what happens when you look for a string in a command?  Can I grep grep?

Let’s try it:

Alpha:~ computerlamp$  grep test /usr/bin/grep

I got nothing back.  So it didn’t fail, but it didn’t work.   That’s because the command grep is a binary, which means there’s generally no text in it.

Now let’s try something else!  Suppose we want to find all strings in the file that don’t match our string.   So following our example, we want all strings in /usr/share/dict/words that don’t have the string way in them.  In this case, we do:

Alpha:~ computerlamp$  grep -v way /usr/share/dict/words

If you do this,  you get a lot of results.  An awful lot of results.

 

 

What are these files?

So in a previous post we talked about the more command. We also saw how if we tried to look at a binary file, we saw

"/usr/bin/more" may be a binary file.  See it anyway?

So now we have a question: Is there a way to find out if a file is a plain text file versus a binary file? Well, this being Linux®… of course there is! It’s called the file command. It uses various tests to try to find out what kind of data is contained within the file. Remember the blog1.txt file from the other post? If we run

Alpha:~ computerlamp$ file blog1.txt

We get:

blog1.txt: ASCII English text

So that means it’s a file we can use the more command on. What if it is a file that ends with .pdf and is still a text file? Well, that’s the magic of the file command. It doesn’t pay attention to the extension (that’s the letters after the dot) but tests the file itself. We can use the file command on any kind of file. Go ahead, try it on anything on your system, see what you get. It just identifies the file, it doesn’t do anything to it.

So you want to run some commands…

Well, we’ve talked about what the command line is…

…so what can you do with it?
Well, given the name, you can do ‘commands’.

There’s lots of built in commands, but we’ll start with a simple one. Open a terminal session (I’ll leave it up to you to find the one particular to your version of Linux®. It generally has the word ‘term’ in the name.)

The terminal has a ‘prompt’, which is a place to type your commands. They usually combine the name of the computer with your username. So it could look like:

  
 Alpha:~ computerlamp$_

So for our first command, we’re going to try echo. This is a fun command, it repeats any words or sentences you give it to the terminal.

Alpha:~ computerlamp$ echo Hi There
Hi There

Alpha:~ computerlamp$ echo How now brown cow.
How now brown cow.

Alpha:~ computerlamp$ echo Star Wars Rocks!
Star Wars Rocks!

Another fun command is rev. If I type it at the terminal, it looks like:

Alpha:~ computerlamp$ rev

Type any string you want and hit enter. You’ll see the reverse of that string show up. For example:

Alpha:~ computerlamp$ rev
abcdef
fedcba

So now it seems you’re stuck in a loop. You need to get out the rev and back to the prompt. You can do this one of two ways, you can hold down control and hit C or D.