Cleaning Packages Laying Around in Linux

These commands might be different from the commands used in your Linux distribution. For Ubuntu: Use the commands below.

sudo apt-get autoremove
sudo apt-get clean
sudo apt-get autoclean

These commands are needed to remove packages (dependencies) laying on the system after a particular package has been uninstalled.

Administrating | Changing Your Linux Password Tip 4

To set or change a password, the passwd command is used. The command syntax looks like this.

root@pve:~#passwd user

To change your password, just enter the passwd command. You will be prompted for your old password and your new password.

root@pve:~# passwd
Enter new UNIX password:

If you have superuser privileges, you can specify a username as an argument to the passwd command to set the password for another user. Other options are available to the superuser to allow account locking, password expiration, and so on. See the passwd man page for details.

PROCESSES: Sometimes a computer will become sluggish, or an application will stop responding. In this chapter, we will look at some of the tools available at the command line that let us examine what programs are doing and how to terminate processes that are misbehaving.

ps - Report a snapshot of current processes.
top -  Display tasks.
jobs - List active jobs.
bg - Place a job in the background.
fg - Place a job in the foreground.
kill - Send a signal to a process.
killall - Kill processes by name.
shutdown - Shut down or reboot the system.

Viewing Processes with ps
The most commonly used command to view processes (there are several) is ps.

root@pve:~# ps
PID TTY          TIME CMD
19902 pts/1    00:00:00 bash
19930 pts/1    00:00:00 ps

TTY is short for teletype and refers to the controlling terminal for the process.

ps x – If we add an option, we can get a bigger picture of what the system is and many more

root@pve:~# ps x
     PID TTY      STAT   TIME COMMAND
       1 ?        Ss     0:00 init [2]  
       2 ?        S      0:00 [kthreadd]

Since the system is running a lot of processes, ps produces a long list. It is often helpful to pipe the output from ps into less for easier viewing. A new column titled STAT has been added to the output. STAT is short for state and reveals the current status of the process, as shown

Process States(State Meaning)
R – Running. The process is running or ready to run.
S – Sleeping. The process is not running; rather, it is waiting for an event, such as a keystroke or network packet.
D – Uninterruptible sleep. Process is waiting for I/O such as a disk drive.
T – Stopped. The process has been instructed to stop (more on this later).
Z – A defunct or zombie process. This is a child process that has terminated but has not been cleaned up by its parent.
A – high-priority process. It is possible to grant more importance to a process, giving it more time on the CPU. This property of a process is called niceness. A process with high priority is said to be less nice because itís taking more of the CPUís time, which leaves less for everybody else.
N – A low-priority process. A process with low priority (a nice process) will get processor time only after other processes with higher priority have been serviced. The process state may be followed by other characters. These indicate various exotic process characteristics. See the ps man page for more detail.

Another popular set of options is aux (without a leading dash). This gives us even more information and many more.

root@pve:~# ps aux
 USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
 root           1  0.0  0.0  10612   844 ?        Ss   09:08   0:00 init [2]  
 root           2  0.0  0.0      0     0 ?        S    09:08   0:00 [kthreadd]

This set of options displays the processes belonging to every user. Using the options without the leading dash invokes the command with BSD-style
behavior.

BSD-Style ps Column Headers (Header Meaning)
USER User ID. This is the owner of the process.
%CPU CPU usage as a percent.
%MEM Memory usage as a percent.
VSZ Virtual memory size.
RSS Resident Set Size. The amount of physical memory (RAM) the
process is using in kilobytes.
START Time when the process started. For values over 24 hours, a date
is used.

root@pve:~# top
 top - 14:24:56 up  5:16,  1 user,  load average: 0.00, 0.00, 0.00
 Tasks: 148 total,   1 running, 147 sleeping,   0 stopped,   0 zombie
 %Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
 KiB Mem:   1013700 total,   429240 used,   584460 free,    24920 buffers
 KiB Swap:  1179644 total,        0 used,  1179644 free,    75512 cached

PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND 
19900 root      20   0 71260 3708 2900 S   0.3  0.4   0:00.03 sshd                    
       1 root      20   0 10612  844  712 S   0.0  0.1   0:00.68 init                    
       2 root      20   0     0    0    0 S   0.0  0.0   0:00.00 kthreadd

The top program displays a continuously updating (by default, every 3 seconds) display of the system processes listed in order of process activity.

More about Linux environment
printenv: This is used in printing more about the environment variables e.g

root@pve:/# printenv
 TERM=vt100
 SHELL=/bin/bash
 SSH_CLIENT=192.168.177.17 53305 22
 SSH_TTY=/dev/pts/0
 USER=root
 MAIL=/var/mail/root

Note: this output can be pipped into less like this (printenv | less)

What we see is a list of environment variables and their values. For example, we see a variable called USER, which contains the value me (root).

root@pve:/# printenv USER
root

Using a Text Editor
All text editors can be invoked from the command line by typing the name
of the editor followed by the name of the file you want to edit. Here is an example using gedit

[me@linuxbox ~]$ gedit some_file


This command will start the gedit text editor and load the file named
some_file if it exists.
Note: Whenever we edit an important configuration file, it is always a good idea to create a backup copy of the file first. This protects us in case we mess the file up while editing. To create a backup of the .bashrc file, do this.

root@pve:/# cp .bashrc .bashrc.bak

It doesnít matter what you call the backup file; just pick an understandable
name. The extensions .bak, .sav, .old, and .orig are all popular ways of
indicating a backup file. Oh, and remember that cp will overwrite existing files silently. Now finding a Package in a Repository by using the high-level tools to search repository metadata, one can locate a package based on its name or description.

Package Search Commands

root@pve:/#apt-get update
root@pve:/#yum search search_string
root@pve:/# apt-cache search apache

Installing a Package from a Repository
High-level tools permit a package to be downloaded from a repository and installed with full dependency resolution
Package Installation Commands

root@pve:/#apt-get update
root@pve:/#yum install package_name

Installing a Package from a Package File
If a package file has been downloaded from a source other than a repository, it can be installed directly (though without dependency resolution) using a low-level tool. Low-Level Package Installation Commands Style Command

root@pve:/#dpkg –install package_file
root@pve:/#rpm -i package_file

Removing a Package
Packages can be uninstalled using either the high-level or low-level tools.
Package Removal Commands

root@pve:/#apt-get remove package_name
root@pve:/# yum erase package_name

Listing Installed Packages
The commands can be used to display a list of all the packages installed on the system.

root@pve:/# dpkg –list
root@pve:/#rpm -qa

Determining Whether a Package Is Installed
The low-level tools shown in Table 14-10 can be used to display whether a specified package is installed. Package Status Commands

 root@pve:/#dpkg --status package_name
 root@pve:/#rpm -q package_name

Storage Media: We will look at the following commands:

mount -Mount a filesystem.
umount- Unmount a filesystem.
fdisk – Partition table manipulator.
fsck – Check and repair a filesystem.
fdformat – Format a floppy disk.
mkfs – Create a filesystem.
dd – Write block-oriented data directly to a device.
wodim (cdrecord) – Write data to optical storage media.
md5sum – Calculate an MD5 checksum.

Troubleshooting Cisco ASA -Commands

Use “show switch vlan” to view the vlans that have been assigned to Layer 2 switch ports.

 TestASA(config)# show switch vlan
 VLAN Name                             Status    Ports
 
 1    inside                           up        Et0/1, Et0/2, Et0/3, Et0/4
                                                 Et0/5, Et0/6, Et0/7
 2    outside                          down      Et0/0
 TestASA(config)#  

Use the show int IP brief to view the configured interfaces

TestASA(config)# show int ip brief
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 unassigned YES unset down down
Ethernet0/1 unassigned YES unset up up

Note on a cisco switch its “show ip interface brief”

use the show ip add a command to view the configured IP address of the interfaces and VLANs

TestASA(config)# show ip add
System IP Addresses:
Interface Name IP address Subnet mask Method
Vlan1 inside 192.1xx.1xx.xx 255.xxx.xxx.0 CONFIG
Current IP Addresses:
Interface Name IP address Subnet mask Method
Vlan1 inside 192.1xx.1xx.xx 255.xxx.xxx.0 CONFIG

To display the configured http server if configured

TestASA(config-if)# show run http
http server enable
http 192.168.176.0 255.255.240.0 inside

To display the configured Telnet connection

TestASA(config)# show run telnet
telnet 192.168.176.0 255.255.240.0 inside
telnet timeout 1000

To display the configured ssh connection

TestASA(config)# show run ssh
ssh stricthostkeycheck
ssh 192.168.176.0 255.255.240.0 inside
ssh timeout 10
TestASA(config)#