Trix' with Linux 0x01 - Basic Linux Use

cli
basic
beginner
networking
linux

(Command-Line Ninja) #1

Welcome to Trix’ with Linux, the first installment of this series! In this series you will become my trainee command-line ninjas and in this guide we will be covering basic Linux use. I will cover Ubuntu/Mint (these will also work for Kali). If you’re using another distro and want help, just comment and I’ll be happy to help you out as will many others here.

Getting Familar

Firstly, now you’ve fired up your new Linux distro, you first must get comfortable and familar with your terminal, open up your terminal application, this can usually be found in a menu or on Mint/Ubuntu by pressing CTRL-ALT-T. Once you are there, you will be presented with a small line of text and a blinking cursor. This line of text is your PS1. On my Arch Linux machine, my PS1 looks like this

[email protected] ~

  • pry is my username, and the current user I am logged in as.
  • ghostpro is the hostname of my machine
  • ~ is the current directory, in Linux ~ (pronounced tilda) represents your home directory. So my documents folder would be located at ~/Documents/, however in actual fact, is located in /home/pry/Documents/, but because I am logged in as pry, the /home/pry/ is replaced with ~.

In most shells, there will be a $ or a # before the cursor, this is used to represent whether you’re logged in as root or a normal user. # represents root, and $ represents ordinary user. Root is like admin. An all powerful superuser who can do whatever he likes. This can be dangerous, so don’t log in as root regularly. This will be covered later on…

Navigation

If your PS1 doesn’t show your current directory, then you can use the pwd command to see what directory you’re in. If I run it on my machine I get this response /home/pry because I haven’t gone anywhere. To see what files are in this directory/folder, I just need to run ls, the response I get is:

Bin Desktop Documents Downloads Music Pictures

This is the same as opening a file manager and going to my home folder. Now, lets say I want to go into my Documents directory, all I need to do is execute cd Documents, cd stands for change directory. Note cd is case sensitive.

Now, if that executed fine, you just now be in ~/Documents/, I like to think of file paths like web paths in URL’s. You start in the home directory, or the home page, and as you click links you can move around them. If you want to verify you have changed directory, quickly run pwd again to see. You should get a response like this /home/pry/Documents. Again, you can run ls to see whats in that folder. If you want to go backward, say back to home, you have two choices, the first is to hand cd an absolute path so:
cd /home/pry/ or cd ~/, both will have the same outcome, or, you can simply go back a level with cd .., .. in Linux is generally referred to as the parent directory, the level above you. You can also get back to your home directory by just executing cd with no arguments.

Installing packages

Installing packages is literally one of the best things about Linux based systems. The use of repositories completely obliterates the old fashioned method of downloading executables and installing them with a wizard. If I want to install a package on Ubuntu/Mint, I will need to use an application called apt-get, or apt in modern versions. To use apt-get I will need root privedges, but remember I said earlier that we shouldn’t be logged in as root often? Because of this fatal dilemma, some smart guy (Todd C. Miller) wrote a program called sudo, which means super-user do. This program allows you to escalate privileges for a single command and then return back to your normal safe user privileges. If you try running apt-get without sudo, and by a normal user, then you will get an error message.

So lets say I want to install a package like say pv, for measuring the progress of my file sharing, I would first update the local repository database:

sudo apt-get update
  • sudo is the privilege escalation command to allow apt-get to run as superuser
  • apt-get is the application used to install packages on Debian/Ubuntu/Mint machines.
  • update is the argument I have passed to apt-get, telling it to update its local respository database.

This command will run for a while, and then finish. Now you are good to go! Simply run:

sudo apt-get install pv
  • install is the argument passed to apt-get, telling it to install
  • pv is the package we want to install.
    This command will run through and ask you if you would like to install it, answer with y, and then enter, and it will install it! Easy huh?

Networking

Now that you’re familar with your new shiny Linux install, lets get right on to the basics of Networking in Linux. Two commands you will come to know and use a lot are ifconfig and ip. ip and ifconfig tell you a lot about your current networking setup, and are useful for many things (including mac spoofing).

If you run ip link, you will get a small overview of your networking devices. My wireless networking devices is wlp3s0b1, yours might be wlan0, it will differ on computer to computer. If I want to see the IP address assigned to my wireless card, all I need to run is ifconfig wlp3s0b1 or ifconfig wlan0, and it will output with several lines showing me infomation about my networking enviornment. The second line of the output is the most important to me right now:
inet 192.168.1.78 netmask 255.255.255.0 broadcast 192.168.1.255

  • inet 192.168.1.78 is telling me that my internet networking address is 192.168.1.78
  • netmask 255.255.255.0 is telling me that the network I’m connected to is using a 255.255.255.0 subnet mask, or that I’m connected to a Class C network with 254 possible hosts, more infomation on netmasks/subnets can be found here.
  • broadcast 192.168.1.255 is telling me that the broadcast address for this network is 192.168.1.1.255

I can also control my networking devices with ip link and ifconfig, to put your devices down, you can use either:

ip link set wlp3s0b1 down

or

ifconfig wlp3s0b1 down

And the same works for putting it up, but you replace down with up :stuck_out_tongue

So that’s all for today my trainee command-line ninjas! Hope you enjoyed this edition of Trix’ with Linux, and as always, bai!

pry0cc


Trix' with Linux 0x02 - Sharing files like a Boss!
(pico) #2

Nice introduction @pry0cc. My two cents

The ~ is almost equivalent to $HOME:

cd ~/Documents
cd $HOME/Documents 

But what you can also do is to specify a username

cd ~pico/Documents

Will change directory to /home/pico/Documents or whatever other location the home directory is set for user pico.

Also cd - is a pretty useful command:

/usr/local/include $ cd /usr/include/linux
/usr/include/linux $ cd -
/usr/local/include $

P.S.: Real hackers install packages with configure && make && sudo make install :stuck_out_tongue:, Just kidding


(Command-Line Ninja) #3

Woah I did not know that! Awesome! That cd - is also something I’ve never heard of. Nice share.


#4

Awesome…Unfortunately my current install of Debian makes me run ifconfig as root…so I have to learn how to do things the ip link way because I don’t feel like typing sudo ifconfig lol :stuck_out_tongue:


(pico) #5

Do you want any user to be able to mess up your network?..


#6

I’m the only user so i’m not concerned about that. I’f someone gains access to my box there’s a lot more things I should be worried about than my network settings.


(Command-Line Ninja) #7

Hmmm perhaps you should be worried… What if they did arp spoofing and redirected your whole network through your box, and then was able to monitor your entire network.


#8

Then i’d get worried.


(Monkey Wrench) #9

That is the ‘future’ command, so definitely worth learning.
(Some of the old-school commands / ways will get deprecated and re-wrapped with time. In the simplest of examples, the same as print went from statement to function in python.)

Also check out:
nmcli (interfaces / connections wrapper - Network Manager CLI)
systemctl (systemd manager, new-school services (etc.) manipulation wrapper)
journalctl (journal query, “new-school approach” to syslog (and more))

All of them can be found in both debian-oids and rhel-oids.


(Command-Line Ninja) #10

Would be worth doing a tutorial here! Perhaps we could do a collab?


(oaktree) #11

lsmod rmmod FTW!


(Monkey Wrench) #12

Sure, why not =)

Assuming from your other ‘Trix’ posts, you already have a structure in mind…?


(Command-Line Ninja) #13

This topic was automatically closed after 30 days. New replies are no longer allowed.