Date post: | 12-May-2015 |
Category: |
Technology |
Upload: | worr1244 |
View: | 104 times |
Download: | 0 times |
Linux for CS majors
by Will Orr
What the fuck is this shit?
Linux is a UNIX-like operating system built from GNU utilities and libraries and the Linux kernel.
Neat, how the hell do I use it?
•SSH/command line•X
Command line? Will hold me I'm scared
Basic usage:• ls [path] - list contents of directory•mkdir <dirname> - make a new directory•cd [path] - change your current working directory•pwd - print your current working directory•rm <filename> - remove files•cp <filename> <newfilename> - copy files•mv <filename> <newfilename> - move files
But what if I want more info about those commands?•man <command>• info <command>
In addition to manpages and info pages, there are docs in /usr/share/doc/<packagename>.
Well this isn't so bad! But how do I read that other documentation?• less <filename> for flat text files• lynx/links for HTML files
Neat! Wait.../usr/share/doc? Where the fuck is my C:\ drive?C drive? Fuck is that shit? Linux doesn't have that Windows-y drive bullshit.
/ - your root directory. Every other directory is a child of //etc - configuration files/bin, /usr/bin - binaries/sbin, /usr/sbin - system binaries/lib, /usr/lib - libraries/mnt or /media - directories where people typically mount drives/usr/share - extra shit (documentation, copyrights, example configs)/dev - device files/tmp - temporary files/var - variable files
Wait...you missed a few...
Yeah, there's /root and /home - those are for users' home directories
Each user can have a home directory to put their files. For most users, this is under /home/<username>. For the root user, this is /root.
root...user?
root is always the username for the administrative userroot can do anything and everythingYou don't fuck with root
root can make system-wide changes, edit any and every file on the system, reboot, poweroff, install packages, etc.
That's nice...what can other users do?
Probably not very much.
They need to be given permission to do pretty much anything. Most programs give all users permissions to execute them (so you can do shit like, run programs).
Normal users can't reboot/poweroff, run programs that interact with the hardware, or edit most files outside of their home directory.
Permissions? I need to be given permission to do stuff on my box?Yes.
Permissions in Linux are pretty simple to understand. Files are owned by both a user, and a group.
If you do a quick ls -l, you can see who owns a file: [ will on charmeleon ] ( ~ ) % ls -ltotal 76drwxr-xr-x 6 will users 512 Mar 17 14:43 Puma/drwxr-xr-x 2 will users 512 Dec 24 15:07 bin/drwxr-xr-x 11 will users 512 Feb 28 16:17 bingehack/drwxr-xr-x 7 will users 512 Apr 7 08:29 blog/
...
Ok, makes sense...but what are the weird collections of letters on the very left?You know those permissions I was talking about? Well that string represents what permissions are set on that file!
Permissions are set relative to the owning group and user. As far as UNIX permissions go, there are three types of users:•The user that owns the file•Users that don't own the file, but are part of the group that
owns the file•Everyone else
The fuck?
Ok, let's actually break this down a little more. Here's a directory listing:-rw-r--r-- 1 will users 2271 Feb 21 23:01 iodine-0.6.0-rc1.diff
•The first 3 characters (not including leading dash) (rw-) represent the owners permissions.
•The next 3, the owning group's permissions•The last 3, everyone else's permissions
I get file ownership...but what do those letters even mean?It's easy:•r - read•w - write•x - execute•- - they can't do whatever permission normally goes in that
space
So in our previous example:-rw-r--r-- 1 will users 2271 Feb 21 23:01 iodine-0.6.0-rc1.diff
Will can read and write to the file, but not execute itAnyone in the users group can read the file, but not write or executeEveryone else can read it too, but not write or execute it
But in those other examples...there was a leading d...Like this?drwxr-xr-x 11 will users 512 Feb 28 16:17 bingehack/
That means that that file is actually a directory.Directories have execute permissions so that you can view the contents of them.
There are other possible leading characters:
•c - character device (think serial port)•p - fifo/pipe (think uh...we'll get to that)• l - link (think windows shortcut)•b - block device (think harddrive)
This permissions thing is pretty cool...but how do I change permissions?•chown <username> <file> - change owner•chgrp <groupname> <file> - change group•chmod +/-<permissions letter> - add or remove permissions
You may see chmod with some strange numbers...permissions can be represented in octal.•4 - read•2 - write•1 - execute
Add them to get octal permissions:chmod 755 /home/will/bin
Neat...but...where can I get a list of all my users and groups?•/etc/passwd contains all your users•/etc/group contains all your groups
NEVER MODIFY THESE DIRECTLY THERE ARE TOOLS FOR THIS OMG YOU'LL BREAK EVERYTHING
• adduser•addgroup
(those are distro specific...also try useradd and groupadd)
WHERE THE FUCK DID ALL THOSE USERS COME FROM OHMIGOD I'VE BEEN HACKED [ will on charmeleon ] ( ~ ) % cat /etc/passwdroot:*:0:0:Charlie &:/root:/usr/local/bin/zshdaemon:*:1:1:The devil himself:/root:/sbin/nologinoperator:*:2:5:System &:/operator:/sbin/nologinbin:*:3:7:Binaries Commands and Source:/:/sbin/nologin
...
Calm down, buddy. You just have a fuckton of system users.Services run as users that aren't root, so that when someone hacks your service, they don't get root access to EVERYTHING.
So...totally random question - how do I edit files?vim
...how do I vim?
This could be an entirely separate seminar, but lemme show you the basics:
•h/j/k/l - move around (makes more sense when you do it)• i - insert text•a - append text•ESC - get out of insert mode•:wq - save and quit•:w - save and not quit•:q! - quit, but don't save
wut
There's also another text editor that's installed called nano, and it's like notepad for the terminal, so you can use that if you want.
How do I install programs?
Assuming you're using a Debian-derivative...
•apt-get install <program>•apt-cache search <program>•apt-get remove <program>•apt-get dist-upgrade
How do I run these new programs?
Type their name at a command line.
If it errors, or if you're confused, try doing <program> -h or <program> --help
Thanks, Will! I'm going to remember none of this!The best way to remember knowledge like this is to use it!•rancor•scorn
I'll also make this slideshow publicly viewable and post a link on news/wiki.
Also:•https://help.ubuntu.com/community•http://wiki.debian.org/•http://www.google.com/•Ask me or someone else on floor