0% found this document useful (0 votes)
13 views131 pages

Managing User Accounts and Disks in Linux

The document covers various aspects of managing user accounts, disks, and server administration in Linux. It includes instructions on creating and modifying user accounts, managing disk partitions, and configuring server settings for remote access and monitoring. Additionally, it discusses networking protocols and their configurations, emphasizing the TCP/IP suite and its components.

Uploaded by

iamspidey0104
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views131 pages

Managing User Accounts and Disks in Linux

The document covers various aspects of managing user accounts, disks, and server administration in Linux. It includes instructions on creating and modifying user accounts, managing disk partitions, and configuring server settings for remote access and monitoring. Additionally, it discusses networking protocols and their configurations, emphasizing the TCP/IP suite and its components.

Uploaded by

iamspidey0104
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Managing User Accounts Department of Computer

Science and Engineering

Linux for Devices


Module-4, Lecture-1

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Managing User Accounts Department of Computer
Science and Engineering

• Creating User Accounts


Adding user with User Manager
Adding user with useradd
Modifying users with usermod
Deleting users with userdel
Department of Computer
Science and Engineering
Managing User Accounts Department of Computer
Science and Engineering

• Understanding Group Accounts


Using group accounts
Creating group accounts
• Setting permissions with Access Control Lists
Setting ACLs with setfacl
Setting default ACLs
Enabling ACLs
Department of Computer
Science and Engineering

• Adding directories for users to collaborate


Creating group collaboration directories (set GID bit)
Creating restricted deletion directories (sticky bit)
Department of Computer
Science and Engineering
Managing Disks Department of Computer
Science and Engineering

Linux for Devices


Module-4, Lecture-2

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Managing Disks Department of Computer
Science and Engineering

• Understanding Disk Storage


Partitioning Hard Disks
Viewing disk partitions
Creating a single-partition disk
Creating a multiple-partition disk
Managing Disks Department of Computer
Science and Engineering

• Using Logical Volume Management Partitions


Checking an existing LVM
Creating LVM logical volumes
Growing LVM logical volumes
Managing Disks Department of Computer
Science and Engineering

• Mounting Filesystems
Supported filesystems
Enabling swap areas
Disabling swap area
Using the fstab file to define mountable file systems
Using the mount command to mount file systems
Mounting a disk image in loopback
Using the umount command
Using the mkfs Command to Create a Filesystem
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering

• Your first primary hard disk usually appears as /dev/sda.


• With RHEL and Fedora installations, there is usually at least one LVM
partition, out of which other partitions can be assigned.
• So, the output of fdisk might be as simple as the following:
Department of Computer
Science and Engineering
Creating a single-partition disk Department of Computer
Science and Engineering

The general procedure:


1. Install the new hard drive or insert the new USB flash drive.
2. Partition the new disk.
3. Create the filesystems on the new disk.
4. Mount the filesystems
• The following process takes you through partitioning a USB flash drive to be
used for Linux that has only one partition
Department of Computer
Science and Engineering

• For a USB flash drive, just plug it into an available USB port.
• Determine the device name for the hard disk: # tail -f /var/log/messages
Department of Computer
Science and Engineering

• From the output, you can see that the USB flash drive was found and
assigned to /dev/sdc etc.
• If the USB flash drive mounts automatically, unmount it: umount /dev/sdc1
• Use the fdisk command to create partitions on the new disk.

• If you start with a new USB flash drive, it may have one partition that is
entirely devoted to a Windows-compatible filesystem (such as VFAT).
• Use p to view all partitions and d to delete the partition
Department of Computer
Science and Engineering

• To create a new partition, type the letter n. You are prompted for the type of
partition
• Choose an extended (e) or primary partition (p). Type the letter p to choose
primary.
Department of Computer
Science and Engineering

• Type in the partition number. If you are creating the first partition (or for only
one partition), type the number 1. You are prompted for the first sector to
start the partition.
• Select the first available sector number (you can just press enter to choose
it). You are prompted for the last sector.
• Enter the size of the partition. Because you are just creating one partition to
consume the whole disk, choose the last available sector. To do that you can
just press Enter to accept the default
Department of Computer
Science and Engineering

• Double-check that the drive is partitioned the way you want by pressing p.

• To make changes to the partition table permanent, type w. This will write the
changes, try to sync those changes with the Linux kernel, and quit fdisk.
• If fdisk cannot sync the partition table on the disk with the kernel, the most
likely reason is that a partition from the disk is still mounted.
Department of Computer
Science and Engineering

• Unmount the partition, and then try running the following command to sync
the disk partition table with the kernel: # partprobe /dev/sdc
• If partprobe does not work, rebooting the computer will make sure the disk
and kernel are in sync.
• Although the partitioning is done, the new partition is not yet ready to use.
For that, you must create a filesystem on the new partition:
# mkfs -t ext4 /dev/sdc1
Department of Computer
Science and Engineering

• To be able to use the new filesystem, you need to create a mount point and
mount it to the partition.

• When you are done using the drive, you can unmount it with the umount
command, after which you can safely remove the drive.
# umount /dev/sdc1
Department of Computer
Science and Engineering

• Set up a USB flash drive to mount automatically every time the system boots.
Edit /etc/fstab and add a line describing what and where to mount. A line you
might add: /dev/sdc1 /mnt/test ext4 defaults 0 1
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Managing User Accounts Department of Computer
Science and Engineering

• Understanding Group Accounts


Using group accounts
Creating group accounts
• Setting permissions with Access Control Lists
Setting ACLs with setfacl
Setting default ACLs
Enabling ACLs
Department of Computer
Science and Engineering

• Adding directories for users to collaborate


Creating group collaboration directories (set GID bit)
Creating restricted deletion directories (sticky bit)
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Managing Filesystem Department of Computer
Science and Engineering

Linux for Devices


Module-4, Lecture-3

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Managing Filesystem Department of Computer
Science and Engineering

• Understanding Disk Storage


Partitioning Hard Disks
Viewing disk partitions
Creating a single-partition disk
Creating a multiple-partition disk
Managing Disks Department of Computer
Science and Engineering

• Using Logical Volume Management Partitions


Checking an existing LVM
Creating LVM logical volumes
Growing LVM logical volumes
Managing Disks Department of Computer
Science and Engineering

• Mounting Filesystems
Supported filesystems
Enabling swap areas
Disabling swap area
Using the fstab file to define mountable file systems
Using the mount command to mount file systems
Mounting a disk image in loopback
Using the umount command
Using the mkfs Command to Create a Filesystem
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering

• Your first primary hard disk usually appears as /dev/sda.


• With RHEL and Fedora installations, there is usually at least one LVM
partition, out of which other partitions can be assigned.
• So, the output of fdisk might be as simple as the following:
Department of Computer
Science and Engineering
Creating a single-partition disk Department of Computer
Science and Engineering

The general procedure:


1. Install the new hard drive or insert the new USB flash drive.
2. Partition the new disk.
3. Create the filesystems on the new disk.
4. Mount the filesystems
• The following process takes you through partitioning a USB flash drive to be
used for Linux that has only one partition
Department of Computer
Science and Engineering

• For a USB flash drive, just plug it into an available USB port.
• Determine the device name for the hard disk: # tail -f /var/log/messages
Department of Computer
Science and Engineering

• From the output, you can see that the USB flash drive was found and
assigned to /dev/sdc etc.
• If the USB flash drive mounts automatically, unmount it: umount /dev/sdc1
• Use the fdisk command to create partitions on the new disk.

• If you start with a new USB flash drive, it may have one partition that is
entirely devoted to a Windows-compatible filesystem (such as VFAT).
• Use p to view all partitions and d to delete the partition
Department of Computer
Science and Engineering

• To create a new partition, type the letter n. You are prompted for the type of
partition
• Choose an extended (e) or primary partition (p). Type the letter p to choose
primary.
Department of Computer
Science and Engineering

• Type in the partition number. If you are creating the first partition (or for only
one partition), type the number 1. You are prompted for the first sector to
start the partition.
• Select the first available sector number (you can just press enter to choose
it). You are prompted for the last sector.
• Enter the size of the partition. Because you are just creating one partition to
consume the whole disk, choose the last available sector. To do that you can
just press Enter to accept the default
Department of Computer
Science and Engineering

• Double-check that the drive is partitioned the way you want by pressing p.

• To make changes to the partition table permanent, type w. This will write the
changes, try to sync those changes with the Linux kernel, and quit fdisk.
• If fdisk cannot sync the partition table on the disk with the kernel, the most
likely reason is that a partition from the disk is still mounted.
Department of Computer
Science and Engineering

• Unmount the partition, and then try running the following command to sync
the disk partition table with the kernel: # partprobe /dev/sdc
• If partprobe does not work, rebooting the computer will make sure the disk
and kernel are in sync.
• Although the partitioning is done, the new partition is not yet ready to use.
For that, you must create a filesystem on the new partition:
# mkfs -t ext4 /dev/sdc1
Department of Computer
Science and Engineering

• To be able to use the new filesystem, you need to create a mount point and
mount it to the partition.

• When you are done using the drive, you can unmount it with the umount
command, after which you can safely remove the drive.
# umount /dev/sdc1
Department of Computer
Science and Engineering

• Set up a USB flash drive to mount automatically every time the system boots.
Edit /etc/fstab and add a line describing what and where to mount. A line you
might add: /dev/sdc1 /mnt/test ext4 defaults 0 1
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Understanding Server Department of Computer
Administration Science and Engineering

Linux for Devices


Module-4, Lecture-4

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Department of Computer
Science and Engineering

Challenges as a server administrator:


Remote access
Diligent security
Continuous monitoring
Department of Computer
Science and Engineering

• Starting with Server Administration


Step 1: Install the server
Step 2: Configure the server
Step 3: Start the server
Step 4: Secure the server
Step 5: Monitor the server
Department of Computer
Science and Engineering

• Managing Remote Access with the Secure Shell Service


Starting the openssh-server service
Using SSH client tools
Using key-based (passwordless) authentication
Department of Computer
Science and Engineering

• Configuring System Logging


Enabling system logging with rsyslog
Watching logs with logwatch
• Checking System Resources with sar
• Checking System Space
Displaying system space with df
Checking disk usage with du
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering

• The following is an example of remotely logging in to johndoe’s account on


[Link]:
Department of Computer
Science and Engineering
Administering TCP/IP Networks Department of Computer
Science and Engineering

Linux for Devices


Module-4, Lecture-5

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Department of Computer
Science and Engineering

• Type of Networks
Wired network
Wireless network
• The general approach to configuring networking in three types of Linux
systems
Desktop/laptop networking
Server networking
Enterprise networking
Department of Computer
Science and Engineering
TCP/IP Protocol Suite Department of Computer
Science and Engineering

• The three basic protocols are the Transmission Control Protocol (TCP),
which handles receiving and sending out communications;
• The Internet Protocol (IP), which handles the actual transmissions; and
• The User Datagram Protocol (UDP), which also handles receiving and
sending packets.
• The IP protocol, which is the base protocol that all others use, handles the
actual transmissions, the packets of data with sender and receiver
information in each.
Department of Computer
Science and Engineering

• The TCP protocol is designed to work with cohesive messages or data.


• This protocol checks received packets and sorts them into their designated
order, forming the original message.
• For data sent out, the TCP protocol breaks the data into separate packets,
designating their order.
• The UDP protocol, meant to work on a much more raw level, also breaks
down data into packets but does not check their order.
Department of Computer
Science and Engineering

• The TCP/IP protocol is designed to provide stable and reliable connections


that ensure that all data is received and reorganized into its original order
• UDP, on the other hand, is designed to simply send as much data as
possible, with no guarantee that packets will all be received or placed in the
proper order.
• UDP is often used for transmitting very large amounts of data of the type that
can survive the loss of a few packets—for example, temporary images,
video, and banners displayed on the Internet.
Department of Computer
Science and Engineering

• Other protocols provide various network and user services. The Domain
Name Service (DNS) provides address resolution.
• The File Transfer Protocol (FTP) provides file transmission, and the Network
File System (NFS) provides access to remote file systems.
• Table 34-2 lists the different protocols in the TCP/IP protocol suite.
• These protocols make use of either the TCP or UDP protocol to send and
receive packets, which, in turn, uses the IP protocol for actually transmitting
the packets.
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering

• Configuring Networks on GNOME and KDE


• Zero Configuration Networking (zeroconf): Avahi and Link Local Addressing
• IPv4 and IPv6
• TCP/IP Network Addresses
• IPv4 Network Addresses
• Class-Based IP Addressing
• Netmask
• Classless Interdomain Routing (CIDR)
Department of Computer
Science and Engineering

• IPv4 CIDR Addressing


• IPv6 CIDR Addressing
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Starting and Stopping Department of Computer
Services Science and Engineering

Linux for Devices


Module-4, Lecture-6

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Department of Computer
Science and Engineering

• Understanding the Linux init Daemon


• Understanding the classic init daemons
• Understanding the Upstart init daemon
• Understanding systemd init
• Auditing Services
• Auditing the classic SysVinit daemon
• Auditing the Upstart init daemon
• Auditing the systemd init
Department of Computer
Science and Engineering

• Stopping and Starting Services


• Stopping and starting the classic SysVinit daemon
• Stopping and starting the Upstart init daemon
• Stopping and starting the systemd daemon
• Configuring Persistent Services
• Configuring the classic SysVinit daemon persistent services
• Configuring Upstart init daemon persistent services
• Configuring systemd init persistent services
Department of Computer
Science and Engineering

• Configuring a Default runlevel or target unit


• Configuring the classic SysVinit daemon default runlevel
• Configuring the Upstart init daemon default runlevel
• Configuring the systemd init default target unit
• Adding New or Customized Services
• Adding new services to classic SysVinit daemon
• Adding new services to the Upstart init daemon
• Adding new services to systemd init
Stopping and starting the Department of Computer
classic SysVinit daemon Science and Engineering

• The primary command for stopping and starting SysVinit services is the
service command.
• With the service command, the name of the service you are wishing to
control comes second in the command line.
• The last option is what you want to do to the service, stop, start, restart, and
so on.
• The following example shows how to stop the cups daemon.
Department of Computer
Science and Engineering

• Notice that an OK is given, which lets you know that cupsd has been
successfully stopped.
Department of Computer
Science and Engineering

• To start a service, you simply add a start option instead of a stop option on
the end of the service command as follows:
Department of Computer
Science and Engineering

• To restart a SysVinit service, the restart option is used. This option will stop
the service and then immediately start it again.
Department of Computer
Science and Engineering

• When a service is already stopped, a restart will generate a FAILED status


on the attempt to stop it. However, as shown in the example that follows, the
service will be successfully started when a restart is attempted.
Department of Computer
Science and Engineering

• Reloading a service is different from restarting a service. When you reload a


service, the service itself is not stopped. Only the service’s configuration files
are loaded again. The following example shows how to reload the cups
daemon.
Department of Computer
Science and Engineering

• If a SysVinit service is stopped when you attempt to reload it, you will get a
FAILED status. This is shown in the following example:
Stopping and starting the Department of Computer
Upstart init daemon Science and Engineering

• The primary command for stopping and starting Upstart init services is the
initctl command. The options are very similar to SysVinit’s service command:
• Stopping a service with Upstart init — In the following example, the status of
the cups daemon is checked and then stopped using the initctl stop
[Link] command.
Department of Computer
Science and Engineering

• Starting a service with Upstart init — In the following example, the cups
daemon is stopped using the initctl stop [Link] command.
Department of Computer
Science and Engineering

• Restarting a service with Upstart init — Restarting a service with Upstart init
will stop and then start the service. However, the configuration file will not be
reloaded.
Department of Computer
Science and Engineering

• Reloading a service with Upstart init — Reloading will not stop and start the
service. It only loads the configuration file again. This is the option to use
when you have made changes to the configuration file.

• Notice that the process ID (PID) is still 2490, which is the same as it was in
the example for restarting the cups daemon because the process was not
stopped and started in the reload process.
Stopping and starting Department of Computer
the systemd daemon Science and Engineering

• For the systemd daemon, the systemctl command will work for stopping,
starting, reloading, and restarting. The options to the systemctrl command
should look familiar.
• Stopping a service with system - In the example that follows, the status of the
cups daemon is checked and then stopped using the systemctl stop
[Link] command.
• Notice that when the status is taken, after stopping the cups daemon, the
service is inactive (dead) but still considered enabled. This means that the
cups daemon will still be started upon server boot.
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering

• Starting a service with system - Starting the cups daemon is just as easy as
stopping it. The example that follows demonstrates this ease.

• After the cups daemon is started, using systemctl with the status option shows the
service is active (running). Also, its process ID (PID) number, 17003, is shown
Department of Computer
Science and Engineering

• Restarting a service with system - Restarting a service means that a service


is stopped and then started again. If the service was not currently running,
restarting it will simply start the service.
Department of Computer
Science and Engineering

• You can also perform a conditional restart of a service using systemctl. A


conditional restart only restarts a service if it is currently running. Any service
in an inactive state will not be started.
• Notice in the example that the cups daemon was in an inactive state. When
the conditional restart was issued, no error messages were generated! The
cups daemon was not started because conditional restarts will affect active
services.
• Thus, it is always a good practice to check the status of a service, after
stopping, starting, conditionally restarting, and so on.
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering

• Reloading a service with system - Reloading a service is different from


restarting a service. When you reload a service, the service itself is not
stopped. Only the service’s configuration files are loaded again
• Doing a reload of a service, instead of a restart, will prevent any pending
service operations from being aborted.
• A reload is a better method for a busy Linux server.
• Now that you know how to stop and start services for troubleshooting and
emergency purposes, you can learn how to enable and disable services
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Configuring an NFS Department of Computer
File Server Science and Engineering

Linux for Devices


Module-4, Lecture-7

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Department of Computer
Science and Engineering

• Configuring an NFS File Server


Installing an NFS Server
Starting the NFS service
Sharing NFS Filesystems
Configuring the /etc/exports file
Exporting the shared filesystems
Securing Your NFS Server
Opening your firewall for NFS
Allowing NFS access in TCP wrappers
Configuring SELinux for your NFS server
Using NFS Filesystems
Mounting an NFS filesystem at boot time
Using autofs to mount NFS filesystems on demand
Unmounting NFS filesystems
Department of Computer
Science and Engineering

An NFS file server provides an easy way to share large amounts of data
among the users and computers in an organization. An administrator of a
Linux system that is configured to share its filesystems using NFS has to
perform the following tasks to set up NFS:
1. Set up the network
2. Start the NFS service.
3. Choose what to share from the server
4. Set up security on the server
5. Mount the filesystem on the client
Department of Computer
Science and Engineering
Installing an NFS Server Department of Computer
Science and Engineering

• # yum install nfs-utils


• To find out more about the nfs-utils package, you can run the following
commands to see information about the package, configuration files, and
commands, respectively:
• # rpm -qi nfs-utils
• # rpm -qc nfs-utils
• # rpm -ql nfs-utils | grep bin
Starting the NFS service Department of Computer
Science and Engineering

• The basic NFS service in Fedora is called nfs-server.


Department of Computer
Science and Engineering

• In Red Hat Enterprise Linux 6, you need the service and chkconfig
commands to check, start, and enable the NFS service (nfs).
• The following commands show the nfs service not running currently and
disabled:
Department of Computer
Science and Engineering

• As mentioned earlier, the rpcbind service must be running for NFS to work.
So, you could use the following commands to start and permanently enable
both the rpcbind and nfs services
Sharing NFS Filesystems Department of Computer
Science and Engineering
Department of Computer
Science and Engineering

• To share an NFS filesystem from your Linux system, you need to export it
from the server system.
• Exporting is done in Linux by adding entries into the /etc/exports file.
• Each entry identifies a directory in your local filesystem that you want to
share with other computers.
• The entry also identifies the other computers that can share the resource (or
opens it to all computers) and includes other options that reflect permissions
associated with the directory.
Department of Computer
Science and Engineering

• Remember that when you share a directory, you are sharing all files and
subdirectories below that directory as well (by default). So, you need to be
sure that you want to share everything in that directory structure.
• There are still ways to restrict access within that directory structure
Configuring the /etc/exports file Department of Computer
Science and Engineering

• To make a directory from your Linux system available to other systems, you need to
export that directory. Exporting is done on a permanent basis by adding information
about an exported directory to the /etc/exports file. The format of the /etc/exports file
is:

• where Directory is the name of the directory that you want to share and Host
indicates the client computer to which the sharing of this directory is restricted.
• Options can include a variety of options to defi ne the security measures attached to
the shared directory for the host.
• Comments are any optional comments you want to add (following the # sign).
Department of Computer
Science and Engineering

• As root user, you can use any text editor to configure /etc/exports to modify
shared directory entries or add new ones. Here’s an example of an
/etc/exports file:
Exporting the shared Department of Computer
filesystems Science and Engineering

• The -a option indicates that all directories listed in /etc/exports should be exported.
• The -r resyncs all exports with the current /etc/exports file.
• The -v option says to print verbose output. In this example, the /pub and /home directories
from the local server are immediately available for mounting by those client computers that
are named (maple and spruce). The /mnt/win directory is available to all client computers.
Securing Your NFS Server Department of Computer
Science and Engineering

Some of issues included:


• Remote root users
• Unencrypted communications
• User mapping
• Filesystem structure exposed
Opening your firewall for NFS Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Distributed Network Department of Computer
File Systems Science and Engineering

Linux for Devices


Module-4, Lecture-8

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Department of Computer
Science and Engineering

• Parallel Virtual File System (PVFS)


• Coda
• Red Hat Global File System (GFS and GFS 2)
• GFS 2 Packages (Fedora Core 6 and On)
• GFS 2 Service Scripts
• Implementing a GFS 2 File System
• GFS Tools
Department of Computer
Science and Engineering

• GFS File System Operations


• GFS 1
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Distributed Network Department of Computer
File Systems Science and Engineering

Linux for Devices


Module-4, Lecture-9

By: Dr. A K Yadav (9911375598)


Dept of CSE, ASET, AUUP
Department of Computer
Science and Engineering

• Parallel Virtual File System (PVFS)


• Coda
• Red Hat Global File System (GFS and GFS 2)
• GFS 2 Packages (Fedora Core 6 and On)
• GFS 2 Service Scripts
• Implementing a GFS 2 File System
• GFS Tools
Department of Computer
Science and Engineering

• GFS File System Operations


• GFS 1
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering

You might also like