Welcome to Jack Heart's secret Linux and FOSS Page. This page was made as a way to keep notes about Linux systems and various open source packages that work with linux. Please Enjoy your stay. Please read at least the next section about assumptions of what you know.
This page assumes that:
There are so many other links, but this seems to be a nice one. Here is a link to a complex comprehensive how to on linux. Feel free to scrap my page and use these guides, which are written by others way more experienced then I.
Terminal is the software that allows for the user to use a shell command line interface where they can type commands that are interpreted by the computer operating system, and used to perform functions. Another word for terminal is console. There are primarily 3 ways of accessing a terminal:
A Shell is a program or package that interprets commands and executes them based on the language of the shell. Shell command language is the language and format of how you type in the terminal.
In a terminal window, there is a command prompt which uses a shell command language such as bash. Here is how it looks:
user ~ $
Here is a breakdown of a common command prompt elements
On this page the commands will be in gray boxes. This is what you would type after the $ or #. Sometimes the prompt syntax is included in the box, but the idea is you can copy the box easily
Syntax is the formula and rules made up of a word, words, symbols, combinations and organizations that used in the proper order will perform a command
Once you are in the terminal, and have entered a command, you need to hit Enter to execute it. Here is an Example where the user would type “echo Hello world” and then hit the Enter Key:
User ~ $echo Hello world Hello world User ~ $
After the command is executed, the shell is ready for another command.
Here are some example commands
The echo command displays text. it would normally be followed by the text to display.
echo
ls is a simple command which means list. This will list all the files in your current directory. Many of the commands are abreviated or seem to not represent what they do at all.
ls
This command means you are going to use the package apt-get, which is really called Advanced Package tool with a second aspect of get. There could be other versions like apt-cache which does something different.
apt-get
Most commands require spaces between the different commands, options, operators, etc. This command means you will be changing directory, and documents is the directory to change to.
cd documents
Options modify behavior. A Dash ( - ) is usually an option followed by a letter or letters. This is not exclusive. The command, option, argument, and/or parameter are all separated by spaces.
This command will list all files in the current directory, showing also hidden files and folders (try just ls for example.)
ls -a
You can often combine multiple options. This command will list all the files in the current directory, and give you a human readable size format.
ls -a -h
You can also execute it as:
ls -ah
Many options allow you to enter in a value or string after the option, and often it is required. example:
ping 8.8.8.8 -i 5
This will ping the IP address 8.8.8.8 at 5 second intervals. If you do just the -i, you will get a syntax error. And most commands have a default parameter, in pings case, the interval is 1 so if you do not specify, it will do intervals every 1 second.
Arguments are items which the command acts on. Also separated by space. For example, you could do ls [dir] and output will list that directory instead of your current directory. This command will output all files in /etc/ regardless of your current directory
ls /etc/
In this document, and many other linux documents, brackets [] indicate options. Example:
ls [options, -a, etc]
This means you have some options, which either are listed in the example, or listed below the example of the different options. Another way indicated is angle brackets <>
Directories are discussed more below, but sometimes a directory might be indicated in an example, or as the language of a command. Often it might just be something like /dir, or <path> or just “directory”. This should be easy to interpret. Just remember that you DO NOT always use the example given.
This concludes the section about command line and how it is used. From here on out are notes about the different commands, tools, packages and tips on how to use terminal.
What are commands?
WIP
One of the most useful tools is to view the manual of function, package, or command and all of its options is man.
man [command]
For example, this command will show you the manual for the command echo:
man echo
Your terminal window will now open the document you can scroll up and down, read and copy if you want. To quite out of manual just hit q. Sometimes it is easy to open a second terminal window just to have the man page up. Most man pages are located in /usr/share/man. And there is a command to figure out its location, but an even easier way to examine the man page is to save it as a text file in your current working directory and then view it by a word program. You can save the man by doing > [file] after the command. This way you can easily open it with a word program in your current directory. For example
man fdisk > manfdisk.txt
Another way to view the man page is to do a web search with the same syntax as the bash command
Linux is a general term used to describe a system used by many distributions. A distribution (distro) is a kind of operating systems that functions in the linux system. For example, here are some distributions:
There are so many different distros, version, and forks of distros. A very good website to learn about the distros is https://distrowatch.com.
Many of the tuturials on this wiki work well with debian and a lot of RHEL systems. A lot of tools are very universal, such as cd, or ls. One thing to keep in mind is how the distributions work. A key way of thinking is:
Debian is a linux distribution, but a linux distribution is not always Debian
The file structure listed here is generally for Debian. But many situations are similar in other distributions.
Here are some locations pertaining to the linux system:
Here are locations pertaining to the user:
Additionally, don't go trying to remove a program 1 file at a time. Using packages managers and instructions from there will help eliminate program files.
When you are in command line, you are always in a specific directory. This is indicated by the terminal command. Here is an example of how it may look. You would type prompts after the $
user1@host:/home/user1/Documents$
This means you are in the /home/user1/Documents directory. Not all systems will display the entire directory you are in
pwd stands for print working directory. THis will tell you where your working directory is
pwd
ls Lists files in directory. The default list will show you your current working directory
ls [option]
Options:
Here is a great common way of using ls:
ls -lha
cd [/dir,$dir,.,..,etc] cd is followed by what directory you want to go to this will send to the home directory:
cd ~
This will send to subfolder of current directory. You do not need to include/ unless its a secondary sub directory:
cd <subfolder>
To Change to the parent directory of wherever you are at, aka go up a level, use the ..
cd ..
More info about cd can be found at http://www.linfo.org/cd.html
Copy works like a lot of the other file commands.
cp <file/dir> <newfile/dir>
You can also copy all the contents of a folder, but not the folder itself by doing:
cp /dir/* /newdir
A little trick with cp is you can use it to zero out or truncate a file without changing its location or permissions by copying dev/null to it.
cp /dev/null /path/to/big/ass/file
More about this technique can be found here: https://unix.stackexchange.com/questions/305017/cp-large-file-to-dev-null-to-reduce-size-to-zero
Move works the same way as copy
mv /dir /newdir
For renaming, you need to use move command
mv [original filename] [newfilename]
It is good to use the -T flag when using rename to help with not having folders move to sub folders
mv -T /home/user/oldfolder /home/user/newfoldername
you an do the same for rename, but use cp to make a copy. ex:
cp somethingcfg somethingcfg.backup
Remove is to delete. It does not go to trash unless you have a trash option configured. be very careful with this command
rm [-option] [file]
Options:
Usually a space denotes the next chain of commands or options, but if a file or folder has a space, this can be problematic (which is why anything set or changed by you should usually have no spaces, and is best to be all lower case) But you can indicate spaces with \. Here is an example:
mv /home/user/The\ file.rtf /home/user/documents/
Note that you still do the space after the \
Disk Free shows you how much is free in the main systems.
df [opts] <dir>
Options:
You can indicate the directory you want to view, but a good common tools is to use /. for example:
df -h /
Disk Usage is about seeing what is used in a directory
du [options] <dir>
Options:
Note, simply doing du will list every folder and its size and could take time to show. Here is a very good example how to find the size of a specific folder and all its contents:
du -sB M [/target/directory]
You May want to make a text file with this example. This will not make a loop because it makes the file first from the readout, then places it in that location.
du /home/user > /home/User/dureadout.txt
Another good common example to show you all subfolders sizes in megabytes and sort by size is:
du -h --max-depth=1 /home/user/ | sort -n
File system table or fstab, is a file that tells the system what to mount during startup or when reloaded into the overall linux configuration. It is located in /etc/fstab and can be edited. Here is the basic idea behind each line with spaces between each option:
Examples:
/dev/sda /mnt/external ext2 ro,nouser 0 2 UUID=<number> /home/ext1 vfat defaults 0 0
Each parameters option is listed here:
Once you are done editing the fstab you can restart your computer, or run this command to have the computer mount all that is in it:
mount -a
Spaces in fstab folder or file names are not easily identified with the standard \ charactor. Instead you have to use \040. Example:
To list all UUID and file types, do:
blkid
Fdisk is a very good utility to list drives active on the computer, regardless of how they are formatted or mounted.
fdisk [option]
Options:
Using -l is a very useful option.
fdisk -l
One thing you may want to do is figure out if a drive is a Solid state or not. you can find out if it is Rotational with this:
cat /sys/block/sda/queue/rotational
Replace sda with the desired drive. if this command returns a 0, it is not rotational, 1 if it is.
Mount lets you mount external drives that do not get mounted automatically
mount [options] </device/dir/> </mount/dir>
Options:
Tip: make a directory where you want to mount before mounting. This is often in /mnt. But can really go anywere, baring permissions.
Unmount lets you dismount a folder that may have been mounted through the mount command or fstab.
umount [dir]
Options:
Troubleshooting. if you get the error: umount.nfs: [dir]: device is busy. Try this: http://oletange.blogspot.com/2012/04/umount-device-is-busy-why.html
dd writes data to a disk or file. It does it mostly bit for bit. It is good for creating or writing disk image files from or to disks. It is also very good for wiping free or entire data.
dd if=[input file/folder] of=[output file/folder] [options]
Options:
Input and output files are directories but can also be entire partitions and drive. Most dd practices are for writing to entire drives. A common practice is to write bootable linux images or to wipe a drive.
You can fill a drive with all zeros with dd. This may take a while, as it is making every bit of data 0. You just make the output folder the directory of the drive. You can use fdisk to figure out the drive folder. Here is an example where the external drive is /deve/sdb/:
dd if=/dev/zero of=/dev/sdb bs=1M
If you are wiping your hard drive for security, you should populate it with random data rather than zeros. This is going to take even longer than the first example.
dd if=/dev/urandom of=/dev/sda bs=1M
If you want to just write random data to any free space you can run this command. It is custom and a best practice to wipe just free space. The entire purpose here is the write random data to parts of a disk that are marked for overwriting. In most drive systems, when you delete a file, the actual drive system only marks the area of the drive as available to be written over, but does not actually delete the data. This procedure below will write over all that data and then by deleting the files, allow that space to be written over. This is very helpful because there are packages such as testdisk and photorec that can recover data. Below is an explanation of each command by line:
dd if=/dev/urandom of=r.small.file bs=1024 count=102400 dd if=/dev/urandom of=r.file bs=1024 sync ; sleep 60 ; sync rm r.small.file rm r.file
Explanation: If using this method, it creates 2 files, one that will fill the entire empty space, and one as a kind of buffer.
You can use this command to remote dd with ssh. since dd just makes a copy, it can be joined with a pipe to do other things. In this example it creates a high compressed version with gzip, but for pure copies, you can remove that part:
dd if=/dev/sdb | gzip -c --fast | ssh user@ip 'dd of=/home/user/sdb.img.gz'
Just use the option “status=progress” to see the status. For example:
dd if=somefile of=otherfile status=progress
If for some reason that does not work, you can use this work around for seeing the status. Do this command in a different terminal
kill -USR1 [pid of dd]
Combine this command with the command “watch” (see below) and this will give you interval status instead of just once. But this is stupid and you should just use the status option.
Most modern disks have SMART disk diagnostics built into the drive firmware. You can install the smartctl software to see diagnostics and perform tests. Read more here: https://www.thomas-krenn.com/en/wiki/Analyzing_a_Faulty_Hard_Disk_using_Smartctl. This comand shows a lot of info about a target drive.
smartctl -a [dev/sdX]
And if you want to run a test
smartctl -t short [drive]
Badblocks is used for checking and indexing bad blocks of a hard drive. This will also attempt to fix bad blocks by writing over them and checking if that data is correct.
badblocks [-options] [target drive]
Some common options are:
example for checking an already formatted drive. This will cause you to loose all your data:
badblocks -wsv -o badblocksindex /dev/sdc
Bash is the most commonly used shell command system, though there are other like zsh. Once you have accessed a terminal, you can type in commands with a specific command line format. Almost all Linux based distros are going to use the same language, even with zsh or others.
You can easily add a custom command to bash by editing the user bash config file located at ~/.bashrc
Just add lines to bottom of that file
alias [customcommand]='[commmand]'
For example, adding this line will make it so when you type remote host, it will execute the ssh command in single quotes
alias remotehost='ssh user@remotehost.net'
When finished you may need to reload the bash rc for the command to work:
. ~/.bashrc
(yes, this is correct with the . as the first part of the command)
To list paths of scripts/commands can do
echo $PATH
If you are running something in terminal that continues but you you want to stop and go back to command line, you can invoke a command to terminate the child process. In some instances you may want to try other things to exit the process, but in many cases you can always hit ctrl + C. Sometimes this is not a good thing, like if you are running an update. Other times it is perfectly acceptable like if you do a ping without number of pings.
Different programs offer different ways to copy and past from terminal and into terminal. Many of the terminal programs let you right click or choose from terminal window menus.
Looking back at previous commands can be helpful. You can use history to shows history of users commands history You can also press the up key to go to the previous commands one at a time.
These are common options followed by a command.
These are signals you can include in your command to do certain fuctions. Most of these are Bash or similar type operators.
The symbol && will do a command, then do the next command. This example will display text, wait 5 seconds, do the next echo, then go back to terminal:
echo "hello world" && sleep 5 && echo "your still here?"
You can use this for chaining command together. Not grep or pipe (see below for that)
Wildcards are a kind of regular expression (see next section) and are very usefully when looking for text in a file, or the file name. Not all commands allow wildcards, but here are some examples that do.
This is a wildcard used to fill in any number of characters, or even none. For example this command will list any file in the current directory that has the .txt format:
ls | grep *.txt
This will list any file in the current dir that start with January
ls | grep January*
You can put them together also.
ls | grep January*2016*
Regular expressions are special characters for describing a text pattern. These characters are called meta characters. This is a very powerful tool and often used with grep, sed, awk. There is a lot of information about them, but for this tutorial, we can just talk about a few.
brackets will search through a certain range of characters. This example will return results where the word might have those 2 options for the letter n as upper case N and lower case n
grep [nN]ame
you can use dashes to define a range. In this example the search will go through all a-z lower and upper, and all 0-9. You do not need to separate commase:
[a-zA-Z0-9]
Curly Brackets tell you how many times to search for the letters
More about regular expressions to come
When typing in terminal you can start typing one or more letter to a command and press tab to either auto complete or get a list of options for auto complete. Note, if you do not have enough information, and depending on the linux system you are using, pressing tab will not always auto complete.
Cat is a way to read out files to terminal, but not actually open them (like with vi). It stands for Concatenate and makes readouts simpler.
cat [file]
Options
This will show you the file, but only the lines containing the grep string:
cat [file] | grep [string]
Less works the same as cat but starts with the beginning of the file, and you have to press return to see the next lines, and quite to exit back to command prompt (like reading a manual)
less [file]
Cut is like cat, but lets you remove sections of what is seen
cut [opts] [file]
Options:
Sometimes you may want to print out the processes of the readout. You use the right arrow > character to do this.
[command with operators] > /dir/text.txt
If tou want to append to the end of an existing file, you use two arrows
[command with operators] >> textfile.txt
tell lets you output to a file and show output and write to file. Usually used with pipes.
[command with readouot] | tee [dir/file]
Here is a good example and use for this that will print out the dmesg, but also send it to a file in the local directory named dmesg1
dmesg | tee dmesg1
Watch lets you execute a command at a certain interval. It is usually in most linux systems, but may need to be installed. It is very good for seeing readouts at intervals.
watch [-n #] [command]
Options:
A very good example of this is to watch the status of dd. You can see the command starts with kill:
watch -n [#] kill -USR1 [pidof dd]
Screen allows for you to open sessions as a daemon so the terminal window does not need to be open and you can switch between different terminals. Screen is a very useful tool if you are going to do something that will take a long time, like transferring a lot of data. Note that screen is also a serial terminal program so depending on distributions, it may be different. It is the default for ubuntu.
To start the session:
screen
This starts a new screen session. It will look like regular terminal but is infarct a different screen window. When in screen, to do things you just do:
Ctr+a [option]
Options
When back in terminal you can go back aka reattach to the screen sessions with do:
screen -r
Also back in main terminal you can list all the current screen sessions with:
screen -ls
Tail lets you look at the last 10 lines of a file, which can be helpful for looking at log files. Details:http://www.computerhope.com/unix/utail.htm
$tail [-options] [file] * -f monitors file and shows updates or changes * -n [x] shows you the last lines based on x, NOTE, this goes after the file part of the command
A usefull example is something like:
$tail -f access.log | grep good
this reads access.log and pipes to grep to only show lines containing good (like status:good)
You can wait for something such as the above example &&. The number after sleep is seconds
Pipes send one function to another. read more at:
Should do more research here: http://linux.about.com/od/commands/l/blcmdl1_ln.htm
Environemtal Variables (ev) This is a variable that persists for the life of a terminal session. You can see them with:
WARNING. Only change the path variable if you know what you are doing.
https://www.cs.purdue.edu/homes/bb/cs348/www-S08/unix_path.html
Linux uses the unix epoch time which you can see here: https://www.epochconverter.com/clock
This will display the date and time
date
To see the time and date in a specific format do:
date +[FORMATS]
You can also use some different formats. Here is a link to a list: https://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/
ALso, here is a format you might like:
(%s) %Z %z [%V/52] [%w/7] [%m/12] %a %b %F %T
To read out free memory and memory info
Top is a simple readout of tasks and performance. for more advanced cli readout, use htop
vmstat is simple show of some of the processor info.
Gives main system readout of kernal information including x86 vs x86_64, etc
Simple message of components and system stats
lists usb information
Proc files system is a directory in linux that has files with information. The files in the /proc directory are not real files, but rather hooks to look at information available to the kernel. However you can use cat to get some file information.
This command shows you the information of that file. here are what many of them will display if you replace [file] with these:
There are many other readouts you can gather from proc. https://en.wikipedia.org/wiki/Procfs
Based on distros Ubuntu
lsb_release -d
linux mint
inxi -Fxz
debian
less /etc/debian_version
Fedora and redhat
cat /etc/fedora-release cat /etc/redhat-release
Puppy
cat /etc/DISTRO_SPECS
Run paths are the locations your compand system (bash, zshel, etc) look in for basic commands. For finding run paths can do
dmesg (display message or driver message) is a command on most Unix-like operating systems that prints the message buffer of the kernel.
THis is a super complex readout.
Also a very good system readout command. Will work on non x86 systems. Probably need to instal
Find is the most basic search option. It searches file names and folders, but not actual files, use grep for that
find [directory dirs] [expression] [-options]
Options:
find / -name 'file.*' -type f
find *.jpg -o *.jpg
A useful tool is to use the -exec option with find.
find [expression] -exec [bash command] {} \;
Explanation
find [expression] -exec [bash command] {} [continued bash command]
* the ending \; ends the bash command * A good example of how to find all of a file type and move to a dir is: find / -iname *.jpg -type f -exec mv {} /home/user/jpg \;
Locate is a lot faster then find, but has less options.
locate [expression]
Grep is a kind of advanced search where it searches INSIDE the file, not file names or folders. See this link for more: http://www.codecoffee.com/tipsforlinux/articles/25.html grep [-options] [search field] [director] Options
Another advanced option is:
[command with readout] | grep [-options] [search field]
Examples: If you want to only show NON commented out lines, here is a nice little trick:
[readout command] | grep -v '^$\|^\s*\#'
An alternative way do do this if that does not work is to use egrep (this is not perfectly tested):
[readout command like cat] | egrep -v -E "^\s*(#|$)"
This option works very well for most systems and a trick is to add it to your .bashrc file. For example you would add this line to that file:
alias grepc='grep -v "^$\|^\s*\#"'
Notice that the quotes are a little different because it is being interpreted from a file, rather then direct from command line.
Sort is like grep is a good way to sort an output.
Usually used with a pipe. Ex:
Here are some main system commands.
A very common command for shutting down and restart
shutdown [option] [time]
Options:
This example shutdown command is very simple and will restart the computer immediately after you press enter:
shutdown -r now
if you have a systemd system:
systemctl [power options]
Here are some power options:
If you are online, you can set the ntp server:
ntpdate [server]
A common server to use is us.pool.ntp.org. You can also set it to the hwclock with:
$hwclock --systohc
(this is untested)
For fedora to see avialable time zones:
timedatectl list-timezones
Find the timezone you want to use exactly as outputed in list. This is case sensative and you can use the / icon. You can also tab autocomlete.
timedatectl set-timezone [zone]
Vi is a powerful text editing tool in prety much every linux distro. Originally pronounced Vee-Eye.
Vi does not work like popular word processors and you should refer to various web pages on how to use it.
There are three Modes:
In Nav mode:
Another way to find things is:
When NOT in text mode you can type colon : to do certain commands such as:
There are many other commands, but those are the ones I have memorized and will probably be enough to get you around/get you in trouble.
A much easier text editing tool. Still learning
stream editor. You can use this to change text. you can play with this by piping from cat or echo (examples below) But here are the basics:
Note: for when you want / in the word you can use a different character for the /, such as | or _. As in:
There are many other tools for sed, but you can play with them from pipes.
Now you can see that you can change words in documents with sed and by using the > to export to a document. For example say you had a document you wanted to change all the words, like instead of saying “John” you wanted it to say “Mary”
You can also combine with grep so that it will only edit hte lines grep finds:
An easy way to see all users is look in the Home directory and see the list of users.
To see users view file in /etc/shadow. This shows you system users also so can be a bit big. For regular users you might just look in home dir for home users. Here are some other user commands:
Sudo means super user do. This is what you use when you are a basic user but want to do something with elevated privileges. Usually you will be promoted with a password of the super user. To edit the sudoers file use visudo:
To see all users, even non people users
/etc/shadow Debian $ ??
Can use passwd to change your password.
(article in progress)
3 types of enryption tools for linux
http://www.pcworld.com/article/3140023/linux/3-encryption-tools-for-linux-that-will-keep-your-data-safe.html#tk.rss_all
To see a list of all the permissions of a file do:
THe most powerful tool for viewing and changing permissions is chmod:
Some packages, software, etc need keyes you may use gpg as a tool. in this example we will copy a key from another place using a pipe . like a debian key from the main debian keyring, to the apt-key list.
usefull links:
Network interfaces have a name and many commands will default to an interface, or require you to say which interface you want to use. There are a few different ways to list all interfaces and their status. one common ways is:
ifconfig -a
Here are some examples:
With linux networking, ifconfig allows you to make some changes and get some info about the networking. For a readout:
ifconfig
You can temporarily set the IP by using:
ifconfig [iface] [ipaddress] netmask [255.255.255.0] up
Then you need to set the gateway with route:
route add default gw 192.168.99.254
These settings will be lost once the computer restarts
Of course, you may want to set the ip manually. to do this you need to edit /etc/network/interfaces with something like vi. Here is an example script:
auto lo iface lo inet loopback auto eth0 #allow-hotplug eth0 #iface eth inet dhcp iface eth0 inet static address 192.0.2.7 netmask 255.255.255.0 gateway 192.0.2.254 dns-nameservers 8.8.8.8 8.8.4.4
Here is a description of each item
Normally after changing this you can do this to reset it. There are a few ways to do this.
There are a few different ways to restart the interface and depending on your system you may need to use different ones. this is also very helpful for running scripts.
This command is a simple way to enable and disable and interface
A trick if you are remote accessing is running:
Or another is to use the -a for all
Sometimes ifdown and ifup do not work so you may need to do other commands to restart the network service.
This is for systems that use systemctl, but it does not always work:
sudo systemctl restart networking.service
This will perform a restart at the high level of processes. it is effective
invoke-rc.d networking restart
Redhat, centos, etc have a bit different method
This is a more advanced setup and usually made for using multiple interfaces on a server for things like redundancy or increased performance. You will be editing the same debian network config file located at:
/etc/network/interfaces
You need to have this kernal module installed: bonding If you dont have it you can use modprobe to set for the session or set it in the modules file. See in this wiki the section about modprobe
There are several modes you can set. You will need to define the bondoing mode in the config file. You can use either the number or the name in the config file
https://www.ibm.com/support/knowledgecenter/en/linuxonibm/com.ibm.linux.z.l0wlcb00/l0wlcb00_bondingmodes.html
Here are some modes that are most commonly used:
The basics for the config file is to define an bond as an interface. First you define the interfaces, then you define the bond interface.
# The primary network interface auto eth0 iface eth0 inet manual bond-master bond0 bond-primary eth0 # The secondary network interface auto eth1 iface eth1 inet manual bond-master bond0 # The bond with bond configurations and first IP address auto bond0 iface bond0 inet static address 192.168.1.99 netmask 255.255.255.0 gateway 192.168.1.1 bond-mode 1 bond-miimon 100 bond-updelay 200 bond-downdelay 200
Config properties for bonding
You will be editing the same debian network config file located at:
/etc/network/interfaces
You need to have this kernal module installed:
8021q
This is an example of how to use Vlan 700. It is simple. There are other ways of doing it
auto eth0.700 iface eth0.700 inet static address 10.100.10.77 netmask 255.255.255.0
Using the above information, here is an example of how to have 2 different IP addresses on a bond interface of a server, and one of the IPs with a VLAN.
## beginning of interface config file # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eno1 iface eno1 inet manual bond-master bond0 bond-primary eno1 # The secondary network interface auto eno2 iface eno2 inet manual bond-master bond0 # The bond with bond configurations and first IP address auto bond0 iface bond0 inet static address 1.2.3.4 netmask 255.255.255.0 gateway 1.2.3.1 bond-mode 1 bond-miimon 100 bond-updelay 200 bond-downdelay 200 bond-slaves none # Vlan and what bond to belong to: auto vlan670 iface vlan670 inet static address 192.168.0.253 netmask 255.255.255.0 vlan-raw-device bond0
this page indicates some checks that could be done after configuring the interfaces file. https://www.tecmint.com/network-nic-bonding-teaming-in-debian-linux/2/
Mainly it suggests to perform these checks:
Use ip to show / manipulate routing, devices, policy routing and tunnels. Many of the things you do with ifconfig can now be done with ip. Here is a good link, and some examples that will be expanded uppon later.
https://www.tecmint.com/ip-command-examples/
There are a Few ways to change DNS:
Need to edit the file:
/etc/resolv.conf
The file should contain:
nameserver [DNS server IP] domain [Domain Name of local host] search [Which Domain to search]
Network manager or nm is a very common service running to manage networks and give an easy to use gui for network releated operations in linux. It is very common with many distros and perfect for easily connectng wifi or changing IP.
There is a cli for nm that can be usufull.
Located at /etc/network/interfaces. This file tells ifup,ifdown, etc how to control various interfaces. it is looked at during nm startup so some network configs can be put there. example:
nm-online is a wait for connection service that runs during start with nm. to disabled during bootup with its target file:
If you want to modify the confiruation of how this is run during startup, you may need to edit a startup file for nm located at:
Edit to say:
[Service] Type=oneshot ExecStart=/usr/bin/nm-online -s -q --timeout=30
For more info: https://askubuntu.com/questions/615006/ubuntu-15-04-network-manager-causing-slow-boot
Can do ping just like in windows:
Tip: here is how to ping with timestamp
Very similar to windows tracert.
to see host infomration
hostname
Options
For DNS info. if not on system, should install package dnsutils
iwconfig is like ifconfig for wireless. you can do a lot of different things, including finding the status and name of your wireless card.
This tool helps with seeing the different SSIDs
There are many other options, if you do iwlist -h it shows you a nice list.
A very good example to scanning is
Used to see ports and see Ip addresses
Used to show a log of Packet Headers info, not packet itself.
tcpdump
This just gives simple readout of packets. Can be a lot and show you a lot
This example will only show you packets sent from that address.
tcpdump src 192.168.1.1
You can combine src, dst, and nots to get things
tcpdump -i eth0 src not
To sort by mac on ethernet 0 (fist port usually)
sudo tcpdump -i eth0 ether host aa:bb:cc:11:22:33
This is an excellent page for more options: https://danielmiessler.com/study/tcpdump/#gs.lU0pRcE
Use dig to easily lookup what the DNS entry of an ip is.
dig [host] [options]
Some options
Example to look up what IP google has and what Ip it returns:
User@mend:~#dig google.com +short 142.251.46.238
ssh stands for secure shell. It is a service that allows for you to remote access a terminal using encryption. It is very universally standard and exists on most linux systems or can be easly installed
ssh [-p <port>] [username]@[ip]
For example, if you want to access a server at 1.2.3.4 with the username admin:
ssh admin@1.2.3.4
Then you would be prompted to enter a password. There may be other security gates you will need to authenticate with. Once you have acccess the computer you are in the terminal for that host and can do commands as if you were there.
Config file in /etc/ssh/sshd_config
When done with config, do:
service sshd restart
Part of the ssh program is a package called last. You can use it to see the last people logged in, or current logged in users just do:
last
Known hosts is a file in your current user's directory that is for when you ssh into something that is unknown. You can edit this however you want. It is located at
~/.ssh/known_hosts
Sometimes when you reboot devices you may get a warning as the key will be different. Here is a link on how to fix it:
http://www.thegeekstuff.com/2010/04/how-to-fix-offending-key-in-sshknown_hosts-file/
You can edit this file with nano or vi, or use sed to modify it simply this way:
sed -i '[#]d' [/dir/known_hosts]
Where # is the located in the error message line that says :
"Offending key in [dir/known_hosts]: #"
The directory is usually either
~/.ssh/known_hosts or /.ssh/known_hosts
the remote host might not allow you access due to how the encryption works. In this example here is the error:
$ssh user@host Unable to negotiate with host port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
To fix this edit ~/.ssh/config and add at the end:
KexAlgorithms +diffie-hellman-group1-sha1
Note that the file named config may not exist. Just create one and ssh will look at it for that type of configuration, even if it just has one line.
for better security you can create a public private key relationship. Here is an example of how to do this with ssh. Taken from https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2
First, create the key pair on your client machine, as in our computer, NOT where you want to ssh into. Also, it does not matter what user you created. Note: Once you create the key on your local machine, that public key can be copied to multiple machines. So you can skip this step and move the public key to server.
ssh-keygen
Options
When you execute this command, it will give you some steps you need to follow. It wants to create the public key file at ~/.ssh/id_rsa
There are 2 ways. The main way, and the manual way. Here is the primary best practice:
ssh-copy-id [user]@[server address]
Here is the manual way. This is just an example and certain lines would need to substituted:
cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
You can see in the manual way it just takes the public key file and puts it in the .ssh directory.
Now you should test the ssh login. You should then be prompted with a password that is the password of the key you created, NOT the host nor client password
Telnet works the same as ssh, but dont put the password.
ftp is a command line utility for accessing via ftp. An FTP client is usually easier but certain things may need it for access.
ftp [host]
Then you Should be prompted with user name and password. Once you are in ftp, you will have a prompt that looks like:
ftp>
Here are some commands you can use there. This turns it into binary transfer, which is the preferred method for transferring files:
ftp>bin
This will put a file from the directory you initiated ftp and put it in the host.
ftp>put [file]
this will get a file from the host, to the directory you are
ftp>get [file]
To exit
ftp>bye
Note, that some systems have probes that will execute a command such a firmware update, if a certain file name or type is put in the host.
sftp is a ssh protocal that allows you to access file systems from within a file manager.
NOTE:These instructions are NOT for command line, but rather from the address bar of a file manager like PCmanFM or other linux file managers. Simply type in the address bar something like:
ufw or Uncomplicated firewall is a front end for iptables that makes it much easier to set up rules. A really great page with commands can be found here:
https://help.ubuntu.com/community/UFW
Basically you use the ufw command to do certain things. This command shows the status
ufw status
Some system modifiers are:
Doing allow or deny is the main syntax of how you add rules. for example if you want to allow port 22 you would do:
ufw allow 22
you can also tell it protocols
ufw deny 53/tcp
You can also allow or deny ip addresses and subnets with from and the proper ip format. Here is the basics
ufw allow from <target> to <destination> port <port number>
And some examples
allow from 192.168.1.0/24 ufw allow from 192.168.0.4 to any port 22 proto tcp
To Delete a rule simply add it to the same rule as before:
ufw delete deny 80/tcp
These are not necessarily industry standard but may be some good rules to add.
IMPORTANT: keep in mind the status of ufw. It is possible to enable a rule that will block you out. it is best to disable ufw, create rules, and then enable it. Here we will deny all incoming and allow outgoing
ufw default deny incoming ufw default allow outgoing
Then we definitly want to allow port 22 either from all, or an ip:
ufw allow from [ip] to any port 22
You can use that rule to add other ports, as most systems will just need that rule.
Some reference articles:
iptables has a wrapper called ufw that is becoming more popular, especially in the ubuntu/debian community. See above for more about ufw
Location of the iptables startup script:
Would probably usually have to download with apt-get. More can be found here: http://www.linuxjournal.com/content/fun-ethtool
Trying to get this to work to talk over sserial from console port on ubnt edgemax to eth0 on linux lappy
resource: http://www.labnol.org/software/wget-command-examples/28750/
scp is secure copy and is a way to send files from one computer to the other. typically it is:
This information was from:http://www.hypexr.org/linux_scp_help.php
Winscp is a nice gui that lets you access linux servers from windows. You can do SFTP, SCP and others. Remember that sftp will only work if ftp on device is active. Winscp is easy to use if you understand how ssh works.
pscp is for windows and can be run from the comand line. But using WinSCP is easiest
You can download it here:http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Also, here is the best tuturial:http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter5.html
It is a file that needs to be ran from dos. The easiest thing is to run it from the directory it is in:
nmcli is good ifyou have network-manager installed but dont want to use the gui, and use cl instead. Here is a good tuturial, even though it is device specific, it should still work the same:
http://docs.getchip.com/chip.html#wifi-connection
Its easy enough to google whats my ip to find your public IP, but for very small clients, you may not be able to do this. Here is a workaround for how to check if the public IP:
This will call up a website that can display your ip in a simple way. The operators for wget are just quiet and save to a standard file which is then echoed with the echo command.
Simple Network Management Protocol allows you to get information from network devices. You can also use it to control, but this is not the typical way it is used.
To install the suite of packages
To get the status of if snmp and if it is running on a device you need to know the IP of the host, the community string, and the version snmpstatus -c [community] -v [version] [host] For example snmpstatus -c public -v 2c 192.168.0.99
snmpwalk is a tool to scan for snmp. To install you you just install the package called snmp
snmpwalk [opts] -c [community] [ip address] [OID]
Options
snmpwalk will go through every sub OID possible from the highest point you are calling it from. This is very good when discovering sets of data, but if you want to find the specific information of a specific OID, you want to try snmpget. This is very hepful because if you use walk for what you think is specific OID. It might append a 1 or another number on the end. For example, lets say that oid.99.500.3.5 is supposed to tell you how may foos are in the network device so you run:
snmpwalk -v1 -c public 192.168.1.99 oid.99.500.3.5
You might get a return of:
SNMPv2-SMI::oid.99.500.3.5.1 = INTEGER: 33,
You can see that in the readout it shows the oid with a .1 on the end. So if you did snmpget instead:
snmpget -v1 -c public 192.168.1.99 oid.99.500.3.5
This might be a return readout:
SNMPv2-SMI::oid.99.500.3.5 = No Such Instance currently exists at this OID
If you do walk, you may see that the o
To allow your linux device to act as a simple snmp agent you can install snmpd
apt install snmpd
You need to edit a few things in
nano /etc/snmp/snmpd.conf
First you have to edit the Agent Behavior section so snmpd will listen to all connections, rather then local
# Listen for connections from the local system only #agentAddress udp:127.0.0.1:161 #<<<<This is the line to comment out # Listen for connections on all interfaces (both IPv4 *and* IPv6) agentAddress udp:161,udp6:[::1]:161 #<<<<This is the line to UNCOMMENT
If you want to change the community, edit the Access Control Section. You just need to change the word public to what community you want
rocommunity public default -V systemonly
You may also want to change the location and contact under System Information section
sysLocation Sitting at the dock on the bay sysContact Me <me@example.com>
You should then restart the snmp daemon
systemctl restart snmpd <<<ubuntu service snmpd restart <<<<RHEL
Also check to make sure it will start up with the computer
systemctl enable snmpd <<<ubuntu service snmpd enable <<<<RHEL
snmpd supports the View-Based Access Control Model (VACM) as defined in RFC 2575, to control who can retrieve or update information. You The above instructions for editing just the community is very basic, but if you want more access you need to modify the config file to include some things. First we want to map a community the the VCAM module. Here is the format and an example. SECNAME, or security name is arbitrary. In this example we define 2 SECNAMES as local and mynetwork. So only SNMP will go to those networks.
#com2sec [-Cn CONTEXT] SECNAME SOURCE COMMUNITY com2sec local localhost foocommunitylocal com2sec mynetwork 1.2.3.4/24 foocommunity
Then we need to define groups based on the SECNAME and what they are capable of doing. In this example we are defining a group called myRWGroup and saying it can use snmp v1 with the local security name
# group NAME MODEL SECNAME group MyRWGroup v1 local
View defines what OIDs are accessible by what group. This example says that all groups can view all snmp oid available. More detials about the masks can be found in the link below. By saying .1 it will allow anything that starts with .1, which all snmp oid should. By saying 80, we are doing something about limiting the hex code (but not sure what it is??)
#view NAME TYPE SUBTREE [MASK] view all included .1 80
Last, we define access for the groups. Below is a simple best practice way.
#access NAME CONTEXT MODEL LEVEL PREFX READ WRITE NOTIFY access MyRWGroup "" any noauth exact all none none
With all this combined, here is a simple script that can be used. This is very critical when you have advanced monitoring systems like zenoss trying to access things like hard drive space, CPU, etc.
# Replace things appropriate, mostly things that start with foo # This is The View Access Control Model and it maps the commuinity to the VACM module #com2sec SECNAME SOURCE COMMUNITY com2sec local localhost foocommunitylocal com2sec mynetwork 1.2.3.4/24 foocommunity # Groups define paramiters groups have access to #group GROUPNAME MODEL SECNAME group MyRWGroup v1 local group MyRWGroup v2c local group MyRWGroup usm local group MyROGroup v1 mynetwork group MyROGroup v2c mynetwork group MyROGroup usm mynetwork # View defines what is accessable by what group #view NAME/ALL TYPE SUBTREE [MASK] view all included .1 80 # This is for creating the access: #access GROUPNAME CONTEXT MODEL LEVEL PREFX READ WRITE NOTIFY access MyROGroup "" any noauth exact all none none access MyRWGroup "" any noauth exact all all none # SNMP identification paramiters syslocation fooSittingonadockatthebay syscontact fooperson@cool.net
Iperf is a way of transferring bulk benign files to see pure transfer rates. Here is a good tuturial: http://openmaniak.com/iperf.php#iperf-w
iperf [mode] [host] [options]
Options
Example to run iperf as a client and the target host of iperf.he.net
iperf -c iperf.he.net
Netstat tool is more for services, but is very related to network. It lists all the open network streams, ports and IPs for specific PID/services.
A secure socket layer certificate is used to authenticate a website with various authorities that give out certificates. It allows for a url to operate has https within a browser or any service that accesses that domain. This is not really a network tool, but rather a security tool for domains within a network.
A certificate is a file with an encryption key. It uses public key cryptography between the web client, like your browser, and the server, or the website you are trying to access with https. The file is located in a few different locations depending on what system you have. Ultimately though you will be defining where the file is with the httpd.conf file. More about that below
First you must obtain the cert. Certs can be found with some hosting providers like godadd, or with a free service like https://letsencrypt.org/
There is an ssl.conf file but that just has to do with paramiters of how you want ssl to work. You will need to locate the httpd.conf file and make sure that your cert files are pointed to the right locations. here is an example /etc/httpd/conf/httpd.conf configuration:
SSLCertificateFile /root/sslcerts/ca.crt SSLCertificateKeyFile /root/sslcerts/ca.key SSLCertificateChainFile /root/sslcerts/ca.bundle
Some aspects of linux involve modifying the kernal moduals that are loaded.
This will add, remove or modify modules for the kernal.
modprobe [module]
A simple way to see if a specific module is installed is to do:
lsmod | grep [module]
Init management is how linux manages processes and when they start, such as at startup. There is a lot of complexity and difference in this system, but the 2 most common commands for managing startup are:
This is the main command for controlling upstart services and can be found in ubuntu and many debian based distros.
This is the main command for controlling systemd services and can be found in most RHEL distros.
There are a few different popular systems that manage this. Common types are:
Processes have different names for different systems:
More about init below
Most systems have the service command and can do many things:
System D is becoming the most common. Many systems may run an older system like sysv or upstart in conjuntion.
You can run systemd a command to get some information:
to see the log
System V is becoming an older service
Below this section is a lot of info about editing init run levels manually, but it is much easier to do it with chkconfig and systemctl outlined above.
I am not sure which is better or depending on the system you have. but they will make editing run levels much easier. Its worth adding them as packages
This is a simple startup script file that automatically executes at each run level. For simple scripts during startup, you can put them here. It is located in:
Some notes:
This is a very complicated service that you should not mess with unless you know what you are doing.Applicable to debian and sysvinit. Generally you will use:
runlevels:
More details about the scripts themselves:
To list services in a specific run level, you can do:
There are generally 2 kinds of symbolic Links (can only have either S or K, not both):
Run levels are:
Processes are the processes running currently. There are some tools you can use to identify processes and resources
init is the parent of all processes.
This lists available commands
Show live process report
Print status of running processes
For more: http://www.cyberciti.biz/faq/show-all-running-processes-in-linux/
Stands for Process ID
This has to do with runlevels and what run levels are activated in different stages and based on different type sof logins. For more info, go here: http://www.computerworld.com/article/2693438/unix-how-to-the-linux-etc-inittab-file.html
This is what I did: http://forums.debian.net/viewtopic.php?t=29333 \\This is for a Minimal Debian install on a pink laptop I am working on
There are many different ways to end a process that is malfunctioning. Primaryily you will be using kill but here is a link that needs to be read and entered into this process
http://www.makeuseof.com/tag/6-different-ways-to-end-unresponsive-programs-in-linux/
Signal options can either be the command or the number. Example:
Other:
Sometimes Linux systems do crash. here are some ways of recovering depending on the sevarity of the issue:
First Switch to a console window. Al + Ctrl + F1-F6. F7 is your GUI. <br> then Find what process is causing problems. <br> Top can help you see processes: http://mendiculus.info/doku.php?id=linux#top
$top
Where x is an app you suspect. This Can help with determining what processes are active: http://mendiculus.info/doku.php?id=linux#ps
$ ps aux | grep x
These 2 commands are a way of finding the process ID, and then killing it. It is very simple but does not always work.
$pidof [name of process] $kill [pid]
$sudo restart gdm
The supposedly simple and smoothest way is:
Cron Table is a time based job scheduler daemon. You can edit the various cron files (/ext/cron*) but it is best to run:
The first time you run this, it will create a temp file and have you choose what editor you want to use to edit the user cron job file (vi, nano, etc.) Then once you save the file, the crontab will add it to a custom folder in /var/spool/cron/crontab/<userfile> You may have to take into consideration users. Also, once you edit the file and save and exit, it will auto update the cron job system so you do not need to reload the service
The system works by adding lines with instructions. Their are some alternatives, but here are the basics:
#This is an example cron file and lines #as usual, the pound comments out #minute hour dayofmonth month dayofweek command 02 15 * * * echo 'hello world' > /home/[user]/Documents/crontest.txt
This line will echo those words and then export it to a text file in that location. It will do it every day at 3:02 pm. All the Time parameters have a logic behind it, but basically ones filled in will do it at that interval. The more you fill in, the more specific in infrequent the interval.
Packages are the files that make up a program programs. A package may also have dependencies, other packages that are needed to run the specific program. For example a drawing program, and a office composing program may require the same graphics package. Most modern linux systems use a package manager that helps with installing and making sure all the dependencies are met. Advanced package manager, apt, and Redhat Package manager, rpm, are 2 of the most common forms of package mangers. APT can be used with a front end gui such as the very common Synaptic.
You can of course run these from command line
Here is an example
This will check the repository Database structure and system. The repository, is like a list of all the programs available through apt. apt will also gather and check things like where to download them, what the dependencies are, How to install them, version info, and other information. You will get some prompts about what apt is going to do to install the package (in this example, nano) and then it will install it. Read more about software repositories at: http://en.wikipedia.org/wiki/Software_repository.
If you want to see how a package file structure will work, you can download the package (.deb or a zip of some sort) and see how the strucutre is in there. But this will not run some scripts or changes you might need to execute. However, in the root of that open/extracted package should be some kind of script for other changes that might need to be changed.
This is the command for debian based systems to do various package thigns. newer stuff is just apt
You can use apt-get after changing /etc/apt/sources.list or /etc/apt/preferences. This is where the packages and sources are listed. Usually you do update to update the lists from repositories and then upgrade to actually upgrade the software.
To do a search for packages with keywords:
yum is for RHLE, or centos
yum [options] [commands] [package]
Options
Commands
dnf is a new version and can mostly work the same as yum.
You can do this to add custom repositories. Generally you want to add them to a file in any file ending in .list located in /etc/apt/sources.list.d directory. But the main file for listing repository links is located in etc/apt/sources.list file. There is a tool to add repositires.
if you dont have add-apt-repository, you can add it with one and/or of these:
rpm is part of the RHEL package manager system. It has to do with updating and upgrading packages. Also part of manageing repositories
For seeing what is installed:
More good info:https://www.tecmint.com/20-practical-examples-of-rpm-commands-in-linux/
Sometimes you have to manyallyt add a repository link, but if it is in the http format, you need a special pacakge
You can just remove PPAs by deleting the .list files from /etc/apt/sources.list.d directory. or do:
As a safer alternative use ppa-purge (may need to install)
these 2 methods won't uninstall packages that were on the PPA but not on tha official repositories. If you want to remove them, you should tell it to apt:
Last but not least, you can also disable or remove PPAs from the “Software Sources” section in Ubuntu Settings with a few clicks of your mouse (no terminal needed).
In addition to doing this. You may want to check the keys and remove them Located in /etc/apt/trusted.gpg
There are lines that represent defualt packages to do certain things. For example the line x-www-browser will point to a specific browsing package such as firefox or lynx. There are 2 ways of changing defaults.
Many packages have configuration files located in /etc. These config files an be in other places also. They often have the .conf extension. Often you will need to configure a package by editing the config file. Keep in mind to always look at other files the config file is refering to, as their may be more configuration to be done with a package other then its main .conf file.
If you are having issues with a a program or service, you may want to look into how to debug it. Some programs have an option to invoke or a simple test config command. For example, radiusd lets you invoke this command: radiusd -X This will actually start he service and show you the entire processes of what is is doing like checking config files, showing handshakes, showing keys, etc. It can be very helpful to show you errors when they occur.
Terminator is a very common and powerful terminal emulator. Here are some shortcuts:
tar is like a zip program
tar [options] [archive-file] [file or directory to be archived]
Options
There are many combinations and you should use them wisley but the most common to extract a tar.gz into the current folder is:
tar does not natively unzip .zip files so you may need to install:
apt-get install unzip unzip [file.zip] [-d /dir]
Check for disk errors
Mail or mailx are command line tools to send emails. They are Message User agents (MUA) Not to be confused with Mail transfer agent (MTA) such as sendmail or postfix. An MTA must be running in order to send mail (mostly.)
One helpful troubleshooting is the log, located in /var/log/mail(something like .log or .err)
you can install clam av via command line:
You do need to go to /etc/freshclam.conf and putt a # before Example to make it not part of the conf file
A common error for fresh clam is:
So you need to change the /etc/freshclam.conf file to say what directory the db will go in
Then you can do this to change ownership of that directory:
Wine is a kind of vitalization that allows you to install software meant for microsoft windows systems. It does not always work perfectly, but can allow you to run a lot of programs:
There are a lot of other packages and information that was moved away from this page. here is the link Supplemental linux information
For a good time with a simple command line browser, install lynx: http://lynx.isc.org/ This is in the debian repository To Change the startup page:
Redo timezone:debian:
Here is some information about common desktop managers:
A good tool to use after installing cinnamon is dconf-editor (previously dconf-tools)
Changing windows (when cant grab corners)
My Favorite minimal desktop manager is Open box. Here is a good debian article on it: https://wiki.debian.org/Openbox
NOTE: This ONLY applies to open box.http://openbox.org/wiki/Help:Autostart
Note in that document at the bottom that t here are 2 places for the autostart, one for a user, which may not be generated in a stripped down system, and one for any open box instance. Some examples of things to add in a very stripped down version of Openbox. Remember, these are just EXAMPLES and you may want to do more reasearch if you do not know what something means
rc.xml is the file and it is Located in either: /etc/xdg/openbox/ or: ~/.config/openbox/
Menu file is located in ~/home/[user]/.config/openbox/menu.xml It should be very easy to follow the xml type syntax to add a menu item.
In mate you can move your curose close to the corners of a window and then hold the alt key and press the right click on the mouse. This will let you easily resize a window. This is helpful when using mate because the tollerence for the edge when you want to move your mouse to resize is so small its hard to find where you can resize.
There are a few different file managers like PCFman, Nemo, Nautelus, etc.
To change the start directory for at least Nemo and Nautelus
xinput helps you find information about your mouse and keyboard inputs
In Linux Mint you can do a lot of the same keyboard shortcuts as in Microsoft Windows by replacing the Windows key with Ctl+Alt. Ex:
A way to connect to some unix based systems is via a serial connection. There are many ways to do this but here are some helpful commands.
There are a lot of adapters, but a common one is the adafruit adapter: https://www.adafruit.com/products/954
The pinout is:
If you are trying to connect to something like the Pocket Chip, then you want to keep in mind that the RX cable on the USB UART wire gets plugged into the TX port on the client device
Screen is a simple program to use when attaching a serial connect. once you have it connected here is what you do:
This is a simple way to access serial
Example:
To exit:
Using modprobe to remove the computer beep: http://www.thinkwiki.org/wiki/How_to_disable_the_pc_speaker_(beep!)
modprobe beep
The following are very popular packages used in many Linux administration systems.
VNC stands for virtual network computing. It allows you to remote access a computer and its interface. There are several pacakges, but Here we will talk about realvnc.
http://www.realvnc.com
On that web page, if you want the open server, you need to navigate to the bottom and choose legacy software.
This is the command to start the server. it is actually a wrapper for the main command xvnc4. But it has some better system setups
One way to see if vnc is running is this command:
To stop a vnc:
When starting vncserver, it created a password file at ~/.vnc/passwd.
One way to create multiple users to to edit the auto start config file.
Is a simple server that will allow vnc to existing x11 session. here are basic steps:
Apache is a very common webserver. It acts as a daemon that directs network traffic to website files, such as html files.
Located at /etc/httpd/conf/httpd.conf
Example whitelist for a folder:
<Directory [$dir of local]> Order allow,deny Allow from [ip] </Directory>
This is the command used to change userinformation for various website authentication. For example, if you use nagios, it accesses this system for for authentication to access the nagios webpage. Though a service like nagios has a level of permissions, the main user authentication is done through apache.
Postfix is a mail transfer agent. It is a daemon that runs in the background and manages mail. It is often used on mail servers but can also be ran on smaller or local machine and allows you to send mail as if you are running a server. You can also use to to send mail as a smtp relay, using another smtp server. This is very helpful when writing scripts where you want notifications. The smtp relay is to prevent mail being spammed in some situations. Here are some basic instructions: https://help.ubuntu.com/community/Postfix
Postfix requires additiona packages that may not be dependencies, such as:
Note that in some RHEL distros, such as centos, the default configuration will work as long as the service is running.
To send an email use the command “mail” or “mailx” See above for this
avahi is a zero conf daemon that will make it easier to connect to devices
https://en.wikipedia.org/wiki/Avahi_(software)
You can do this by editing the host file. Then you can add the device and set its parameters.
MySQL is a database system, below is info about postgres, another very popular database server. It is a daemon that runs on a system and can be accessed by other programs. It is a kind of relational database and there are many other types, but mysql is probably the most popular. Side note, some commands will say schema, this just means database.
mysqladmin [options]
This is for doing things like setting up passwords
mysqldump [options]
Main command for doing dumps
mysql [options]
This command will bring you into the mysql terminal. Here are its options:
Here is a basic example of how to enter the mysql terminal
localhost$mysql -u root -p Enter password:[for password] Copyright information mysql>
A great list of common commands: http://www.zbeanztech.com/blog/important-mysql-commands
Now you can enter different commands for mysql. Most commands need a semicolon after to end the command. Otherwise you hit enter for other lines of a command, such as entering data for the schema. Here are some examples:
This will give you some good list of common commands
mysql>help
To leave the mysql console
>exit;
This will ist all the current databases
>show databases;
This will now bring you into the database to view and edit. Note that the new command prompt does not indicate what db you are in.
>use [db];
This shows you all the tables of that db.
>show tables;
To create a database
>create database [db name];
This will allow for that db to accessed by the localhost, or whatever server you want, and identified by the password
>grant [levels] on [db].* to [db]@localhost identified by "password"
There are many commands to edit the database. here are some basics, but their is a lot of complex syntax that could fill an entire page like this one. But here are some basic stuff. A very good tool is MySQL workbench made by Oracle and for Windows and Linux that lets you edit the system like you would edit a excel spreadsheet.
Here are some basics about postgres and how to access the postgres command prompt
psql [options]
Some options are
Then issue these commands as needed:
Own Cloud is open source server software that creates a system similar to dropbox or one drive. You can create accounts, quotas and a lot of other things for a local file storage platform. Here is a very easy guide on how to install owncloud on CentOS. It can be installed on debian systems, but this link and secontion on Mendiculus will be the centos way:
Once you have installed you should check to make sure that Apache and mysql are on and will startup.
chkconfig httpd on chkconfig mysqld on
THere is a note I have about the speeds of owncloud and you may need to modify the http config to allow more then 2 megs per second
Also I had to install some php and other moduals manuall. But not sure the instructions for that
You may need to update php. Here is how you do it on Centos: https://www.zerostopbits.com/how-to-upgrade-php-5-3-to-php-5-6-on-centos-6-7/
Owncloud does not have its own service, but rather runs in concurrent with it. So if you want to do service actions for owncloud you can just use apache. The service is called httpd, but you can use apachectl. The simple commands are things like:
apachectl [start|stop|graceful]
The graceful command is the best command for rebooting properly
You can see above the information on how to log into mysql. usually you only need to do this once to create the DB per the instructions.
You need to make sure mysql starts automatically
service mysqld start
The mysql db port used is 3306. The defualt user is root
If you need to view or modify the users list you can execute these commands once you are logged into the mysql server. Here is also how to log into mysql:
mysql -u root -p [enter password] use owncloud; select * from oc_users;
If you need to update a user, like copy from one db to another, this is how you can add a line to that table:
update oc_users set password = '1|[Password key goes here without brackets]' where uid = '[user goes here without brackets]';
For some good system info see this file in the owncloud root dir:
/var/www/owncloud/config/config.php
This will help with finding what sql version you have
Owncloud is usually located in:
/var/www/owncloud /var/www/html/owncloud
The user data is in:
/var/www/html/owncloud/data/[user]/files
A good way to see how much all your users are using is to use du, show in megabytes, and sort by size:
du -h --max-depth=1 -B M /var/www/html/owncloud/data/ | sort -n
occ is a command for doing general owncloud maintenance. More info about it can be found here: https://doc.owncloud.org/server/10.2/admin_manual/configuration/server/occ_command.html#file-operations
IN some instances you have to run it as the apache user, and do the entire command:
sudo -u apache php /var/www/html/owncloud/occ [action]
Some very good actions for it are:
apachectl -k graceful If you are having errors with files you can try to run this:
Need to backup in the own cloud folder
More details:
Config and data can be backed up manually to hopefully an external source. When you do the backups, please make sure to put it in maintenance mode, and Remember to take it out afterwards
sudo -u apache php /var/www/html/owncloud/occ maintenance:mode --on sudo -u apache php /var/www/html/owncloud/occ maintenance:mode --off
If there is an error about posix you may need to update a php package and modify a config file. Here is the command that creats the error:
sudo -u apache php /var/www/html/owncloud/occ maintenance:mode --on [sudo] password for support: The posix extensions are required - see http://php.net/manual/en/book.posix.php
The info on how to fix is: https://framasphere.org/p/400627
What you want to do is put in main mode, then install these packages:
yum install php-process
After install you will need to configure it by uncomment the call to the extension in the file /etc/php/php.ini:
extension=posix.so
Then restart apache
apachectl graceful
The database is a little bit more complicated.
Here are mysql instructions for backing up manually the database:
IF you need to change the directory of the data, here are some basics of the steps. This is the main link that follows this process:
https://doc.owncloud.org/server/10.0/admin_manual/maintenance/manually-moving-data-folders.html
It is best to put the owncloud in maintenance mode and then backup your data, config file, and database. Or better yet, create a snapshot of your vm. Then you need to stop apache which can be done with:
apachectl stop
You need to copy your data to the new directory and make sure the permissions and ownership carry over. There are some ways to do this, but here is a simple command. If you have space issues, you may need to use the move command instead.
cp -rp /olddir/data/ /newdir/data/
Once you have moved the data over, you now need to change a config file and edit some database strings. Please do all this before restarting the service. The config file line you need to edit is this:
'datadirectory' => '/newdir/data/',
You also need to enter mysql to edit the database. There are 2 main things you need to edit. This is an example of the queries you can run:
UPDATE oc_storages SET id='local::/newdir/data/' WHERE id='local::/olddir/data/'; UPDATE oc_accounts SET home = REPLACE(home, '/olddir/data/', '/newdir/data/');
That should be it. Now you can start apache back up. You should run some tests like moving a file into a local computers owncloud folder and making sure it is updated in the right place server.
Sometimes when deleting files there is an error and you can not delete it. It is likely because it is locked or there is a cached problem. The best thing to do is run occ with the “files:cleanup” command. See above. If you want to look at the locked or problematic files you can do this:
mysql -u root -p [enter password] use owncloud;
We want to view the files locks tables. You can view the table headins with
show columns from oc_file_locks;
We want to see the files that have more then 0 in the lock column
select * from oc_file_locks where `lock` < 0 ;
You can use conditionals and variables in the bash command line to execute complex commands. Much of this can be helpful when writing complex bash scripts.
There are 3 main ways to put together commands:
This might be the easiest way to start of, as it works like a pipe. The semicolon is meant to string conditionals together. It is best to show it as an example with if then conditionals:
while true ; do echo hello world ; sleep 2 ; done
That is a single command but when in batch you can see how to type it without the semicolons. In this following I will show indicators for command prompts and how it works. Bash detects a conditional like 'while' and will then allow you to write more commands, and press enter after each line of the function. Then you will be able to write on a new line indicated by the > symbol. As long as the syntax is correct, it will end with the correct command, such as done. The following does the exact same thing as the example command with semicolons:
comandprompt$while true >do echo hello world >sleep 2 >done
We will discuss a lot more about scripts below, but here is what the script would look like to do the exact same command above:
#!/bin/bash/ while true do echo hello world sleep 2 done
Note that all three of these versions would continue until you stop with ctrl+c.
For more about conditional expressions see: https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html
if, then, and while are common programing syntax. you can read more about it here: https://ryanstutorials.net/bash-scripting-tutorial/bash-loops.php
This is an example of using while to show a readout of a command, instead of using watch. This below example will echo hello every 2 seconds until you stop the command with ctrl c.
To Read variables us the $ sign before the variable name. Note that the script will check for all variables before it runs through the commands. Here are examples on how to set commands.
[VARNAME]=[value]
It is case sensitive and best practices to have VARNAME be capital. Example:
BIG=123456
then do:
echo $BIG
will return 123456 Here are some other options:
Example:
NOW=$(date +"%Y-%m-%d")
This will store NOW as the date format indicated so if you run:
echo $NOW
It will return the date
Read promps for input
read [options][varname]
This will make a prompt.
example script:
#!/bin/bash echo what is your name read -p 'Name: ' varname echo hello $varname
Then run:
commandprompt$./scriptname what is your name? Name: [prompt to enter name, press enter] hello [name]
Make sense right?
There are a lot of ways to write a script. It really depends on what you want to accomplish and how you want the script to run or be interpreted. Below is how to make bash scripts. Scipts often rely on conditionals and variable as outlined in the above section. Sometimes you have to ask if you really need a script, or can just make a long command with semi colins. Almost everything you can do in a script will run commands as if you were typing them in the bash command line. The advantage is you make a file that can be executed and edited easily. Other ways to write scripts are with python, or C. But these will need an interpreter that can run those scripts.
Basic beginer script:
#!/bin/bash # [any comments, # is ignored] [bash commands]
example hello world:
#!/bin/bash #Script by Jack heart echo Hello World
Then to make your script executable do:
chmod +x [script name]
sh [Script name, location/scriptname]
Also can do ./[scrip]
ex:
./myscript
not to be confused with .file, which is a hidden file or folder
You can run bin files by doing:
usually use Make (this article is a work in progress)
basic steps to compile and make
Example For hstar ipt-netflow-2.1 example
GRUB is a boot loader that can direct a computer which OS or tool to load.
You can edit some of the grub settings by editing the file /etc/default/grub.
edit the default boot selection you can change the string that says:
You can change the splash screen in linux by changing the line:
If you have grub silent or a 0 for timeout, you can invoke grub by pressing shift
When done editing, you need to run:
Sometimes you may want to reload grub due to a change in hard drive order. you could edit the cfg file but an easy way to update it is:
These instructions were from booting puppy on a very old system that was difficult to install and properly load the OS. This section is not complete and might not make too much sense
Grub Commands:
Load kernel (not linux)
Psubok
So the boot command would be:
Basically, you need to download the ISO. Might eventually try to use arch and follow how to links to build up OS.
From Windows: use tool “pen drive linux”
From Linux
For installing Linux mint with DD see this article: http://community.linuxmint.com/tutorial/view/744
Basically the command is:
Mostly the same as mint, but your card should be fat 32
Here are some basic descriptions and links to the above list of assumptions, outlined here:
You know how to search things for understanding, rather then just copying what is written here.
You have installed linux or have a live version of linux.
You are not afraid of command line, or learning command line.
You understand that these are basic simple notes, not extensive tutorials.