Ubantu basic commands
Ubantu basic commands
### 1. `top`
- **Purpose**: Displays the system's resource usage, showing a real- me summary of the system's
processes.
- **Key Features**:
- Load average
- Number of tasks
- Detailed informa on about each running process (PID, user, priority, etc.)
- **Usage**:
```sh
top
```
You can interact with `top` by pressing keys like `k` to kill a process, `r` to renice, `q` to quit, etc.
### 2. `vmstat`
- **Key Features**:
- Memory
- Paging
- Block IO
- Traps
- CPU ac vity
- **Usage**:
```sh
vmstat
```
You can specify a delay and count to repeatedly update the display, e.g., `vmstat 2 5` (update every 2
seconds, 5 mes).
### 3. `iostat`
- **Purpose**: Reports CPU sta s cs and input/output sta s cs for devices and par ons.
- **Key Features**:
- CPU u liza on
- Device u liza on
- Disk throughput
- **Usage**:
```sh
iostat
```
You can use op ons to display specific informa on, e.g., `iostat -d` for device u liza on.
### 4. `netstat`
- **Purpose**: Displays network connec ons, rou ng tables, interface sta s cs, masquerade
connec ons, and mul cast memberships.
- **Key Features**:
- Ac ve connec ons
- Listening ports
- Network sta s cs
- **Usage**:
```sh
netstat
```
- `-p`: Show the PID and program name of the socket owner
### 5. `sar`
- **Key Features**:
- CPU ac vity
- I/O ac vity
- Network ac vity
- **Usage**:
```sh
sar
```
The `sysstat` package must be installed to use `sar`. You can use op ons like `-u` for CPU usage, `-r` for
memory, etc.
### 6. `fdisk`
- **Key Features**:
- **Usage**:
```sh
```
Replace `/dev/sdX` with the appropriate disk iden fier. Use `m` for help within the interac ve session.
### 7. `mount`
- **Purpose**: Mounts a filesystem.
- **Key Features**:
- Mounts filesystems
- **Usage**:
```sh
mount
```
Each of these commands is powerful and provides detailed insights and controls for system
administra on in Ubuntu.
To troubleshoot system performance issues related to CPU, disk, memory, and network, you can u lize
various Linux commands and techniques. Here is a detailed guide:
#### Tools:
- `top`
- `vmstat`
- `sar`
#### Steps:
- Run `top` and observe the `%CPU` column to see which processes are consuming the most CPU
resources.
- Look for processes with high CPU usage and consider if they are necessary or can be op mized.
- Run `sar -u 1 10` to display CPU usage sta s cs at 1-second intervals for 10 itera ons.
#### Tools:
- `iostat`
- `df`
- `du`
#### Steps:
- Run `iostat -x 2 5` to get extended I/O sta s cs at 2-second intervals for 5 itera ons.
- Look at `%u l` to see if the disk is heavily u lized, and `await` for average wait me for I/O requests.
- Iden fy filesystems that are close to 100% u liza on and consider cleaning up or expanding them.
- Run `du -h --max-depth=1 /path/to/directory` to see the size of directories within the specified path.
- Drill down into directories to find large files that can be removed or archived.
#### Tools:
- `free`
- `vmstat`
- `top`
#### Steps:
- Run `free -h` to see the total, used, and free memory.
- Pay a en on to `available` memory which indicates how much memory is available for new processes
without swapping.
- Look at `free`, `buff`, `cache`, `si`, and `so` columns for available memory and swap ac vity.
- Iden fy processes consuming high memory and consider op mizing or restar ng them.
#### Tools:
- `netstat`
- `i op`
- `ping`
- `traceroute`
#### Steps:
- Run `sudo i op` to see real- me bandwidth usage per connec on.
3. **Test network connec vity with `ping`**:
- Look for packet loss or high latency which can indicate network issues.
- Run `traceroute google.com` to see the path packets take to reach the des na on.
- Iden fy any hops with high latency or packet loss which can indicate network bo lenecks.
- **Check System Logs**: Use `dmesg`, `journalctl`, or check logs in `/var/log/` for error messages or
warnings that might indicate hardware or so ware issues.
- **Review System Updates**: Ensure the system is up-to-date with patches and updates which might fix
performance-related bugs.
- **Consider System Load**: Use `up me` to check the system load average. High load averages can
indicate the system is under heavy use and might need resource scaling.
- **Manage Running Services**: Use `systemctl` to review and manage running services. Disable
unnecessary services to free up system resources.
By systema cally using these tools and steps, you can iden fy and address performance issues related to
CPU, disk, memory, and network on your Ubuntu system.
Troubleshoo ng system login issues can involve several steps to iden fy and resolve the problem. Here is
a comprehensive guide to troubleshoot login issues on an Ubuntu system:
1. **GUI Login Issues**: Problems with graphical login (GDM, LightDM, etc.).
#### Steps:
```sh
```
```sh
```
```sh
```
```sh
```
```sh
df -h
```
- Ensure the user's home directory exists and has the correct permissions:
```sh
ls -ld /home/username
```
- The user should own their home directory, and it should have appropriate permissions (usually `755`).
- Some mes, the `.Xauthority` file can cause login issues. Rename it to create a new one:
```sh
mv ~/.Xauthority ~/.Xauthority.backup
```
#### Steps:
1. **Switch to a TTY**:
```sh
```
```sh
```
```sh
chage -l username
```
```sh
```sh
```
```sh
username:x:1000:1000:User Name:/home/username:/bin/bash
```
```sh
```
#### Steps:
```sh
```
```sh
```
```sh
```
```sh
```
```sh
```
```sh
```
- Ensure that the user has the correct permissions to access the system via SSH.
```sh
ls -ld /home/username
ls -ld /home/username/.ssh
ls -l /home/username/.ssh
```
```sh
chmod 700 /home/username/.ssh
```
- **Reboot the System**: Some mes a simple reboot can resolve login issues.
```sh
sudo reboot
```
- **Check System Logs**: Use `journalctl -xe` to view system logs for any errors related to login a empts.
- **Ensure Account is Not Disabled**: Verify that the account is not disabled by checking `/etc/shadow`:
```sh
```
Look for any `!` or `*` characters which indicate a disabled account.
- **Test with Another User Account**: Check if the issue is specific to one user by a emp ng to log in
with another user account.
By following these steps, you can iden fy and resolve most system login issues on an Ubuntu system.
Troubleshoo ng system boo ng issues can be complex because they can be caused by hardware
problems, so ware misconfigura ons, or corrupted files. Here’s a detailed guide to diagnosing and
resolving boot issues on an Ubuntu system:
#### Steps:
- Check all cables (power, data, etc.) and hardware components (RAM, disk, etc.).
- Ensure the boot order is correct and the boot drive is priori zed.
#### Steps:
- If the GRUB menu does not appear, hold `Shi ` (for BIOS systems) or `Esc` (for UEFI systems) during
boot to access it.
2. **Rescue Mode**:
- If you can boot into recovery mode or a live USB, update the GRUB configura on:
```sh
sudo update-grub
```
4. **Reinstall GRUB**:
```sh
```
```sh
```
```sh
```
- Reinstall GRUB:
```sh
grub-install /dev/sdX
update-grub
```
```sh
exit
```
#### Steps:
```sh
sudo fdisk -l
```
- Check and repair the filesystem:
```sh
```
```sh
cd /mnt
```
#### Steps:
```sh
```
#### Steps:
- If you can boot into recovery mode, check boot logs for errors:
```sh
journalctl -b
```
```sh
dmesg | less
```
#### Steps:
1. **Backup Data**:
- Mount your par ons and backup important data to an external drive or cloud storage.
2. **Reinstall Ubuntu**:
- Choose the `Reinstall Ubuntu` op on to preserve your data or `Erase Ubuntu and reinstall` for a clean
slate.
- **Check Hardware Health**: Use tools like `smartctl` to check the health of your hard drives.
```sh
```
- **Check for Memory Issues**: Use `memtest86+` from the GRUB menu to test your RAM.
By systema cally following these steps, you can diagnose and resolve most boot issues on an Ubuntu
system.
System logs are crucial for diagnosing issues and understanding the behavior of your Ubuntu system.
Here's a detailed guide on how to troubleshoot using system logs:
#### Commands:
```sh
```
```sh
```
```sh
sudo journalctl
```
```sh
sudo journalctl -b
```
```sh
```
```sh
sudo journalctl -f
```
```sh
```
```sh
```
```sh
```sh
```
```sh
```
```sh
```
```sh
```
```sh
```
```sh
```
```sh
```
```sh
```
```sh
```
```sh
```
Ubuntu uses `logrotate` to manage log file sizes and archival. Configura on files for log rota on are
located in `/etc/logrotate.d/`.
#### Check Log Rota on Configura on:
```sh
ls /etc/logrotate.d/
```
```sh
cat /etc/logrotate.d/syslog
```
#### Tools:
1. **Install Logwatch**:
```sh
```
2. **Configure Logwatch**:
```sh
```
Troubleshoo ng network connec vity issues in Ubuntu involves a systema c approach to iden fy where
the problem lies, whether it's a hardware issue, a so ware configura on problem, or an external
network problem. Here's a detailed guide:
#### Steps:
- For wireless connec ons, ensure the device is within range of the access point.
```sh
ip link show
```
```sh
```
```sh
```
#### Steps:
ip addr show
```
```sh
sudo dhclient -r
sudo dhclient
```
#### Steps:
```sh
cat /etc/resolv.conf
```
```sh
nslookup google.com
dig google.com
```
```
```sh
nameserver 8.8.8.8
```
#### Steps:
```sh
ip route show
```
```sh
```
```sh
ping <gateway_ip>
```
#### Steps:
```sh
```
```sh
```
```sh
```
```sh
sudo iptables -L
```
#### Steps:
1. **Ping Test**:
```sh
ping <local_ip>
```
```sh
ping google.com
```
2. **Traceroute**:
- Trace the route to an external server to iden fy where the connec on fails:
```sh
traceroute google.com
```
```sh
telnet google.com 80
```
or
```sh
nc -vz google.com 80
```
#### Steps:
```sh
iwconfig
```
```sh
```
```sh
```
```sh
lshw -C network
#### Steps:
```sh
```
```sh
```
#### Tools:
```sh
```
2. **`nmap`**: Network scanner.
```sh
```sh
```
```sh
```
- **Use a Different Network Interface**: If available, try using another network interface (e.g., switch
from wired to wireless).
- **Consult Network Equipment Logs**: Check the logs of routers, switches, or access points for any
anomalies.
By following these steps, you can systema cally diagnose and resolve network connec vity issues on
your Ubuntu system.