You are on page 1of 39

mkfs Command in Linux

 The mkfs command stands for “make file system” is utilized to make a


file system on a formatted storage device usually, a partition on a hard
disk drive (HDD) or it can also be a USB drive, etc.
 A partition is logically an autonomous part of an HDD.
 An organized segment is one to which a low-level arrangement or format,
additionally called a physical format(organization), has been applied.
 It comprises separating the disk’s tracks into a predetermined number of
divisions and filling the information zone of every segment with dummy
bytes. 
 These outcomes in the demolition of any current information on the disk.

When the “mkfs” command is compiled, then a precise list of standard


directories is created, and therefore the specified program is searched for from
the same list.
Syntax for mkfs command:
mkfs [ -V ] [ -t fstype ] [ fs-options ] filesys
[ blocks ]

 The items in the square brackets are discretionary, but the main obligatory
argument is “filesys”. filesys is the name of a device document (i.e., a record
that the system uses to execute admittance to a physical device), for
example, /dev/hda3, the third segment on the primary HDD, or/dev/fd0, the
principal floppy disk. It can likewise be the mount point (i.e., where it is
joined to the system) for the new file system.
 The most commonly used option is “-t”, which is utilized for specifying the
type of file system to be created. If this option is not used, the default
filesystem created will be ext2 (second extended file system) from the other
types of file systems that can be created like ext3, minix, msdos, vfat and
xfs.
 The -V option is used to produce verbose output, and also includes all file
system-specific commands that are executed. By specifying this option more
than once, the execution of any file system-specific commands can be
prevented.
 The “-c” option, will check the storage device for bad blocks before creating
the file system, and the “-l” option, will read the bad blocks list from a file
whose name follows it.
 “fs-options” stand for file system-specific options that are to be passed to the
real file system creation program (i.e., the program for which mkfs is serving
just as a front end).
 
 In the modern era, the way of utilizing mkfs is to type “mkfs.” and then the
name of the file system you wish to create.
 Now, in order to see all the file systems offered by the “mkfs” command, hit
the Tab key twice.
 The list of all available file systems available in the Linux distribution being
used will be displayed in the terminal window. The screenshot is from
Ubuntu 18.04 LTS. Other distributions may have more or fewer options:

To make a File System on a USB:

1. Finding the required device on the OS through the terminal.


 Type in the following command, and it will show all the disk
nodes that are currently mounted.
 Be always sure in choosing the right disk or otherwise, you
can remove the storage device and then again plug it in if the
above command is not showing it in the list, thereafter again
run the above command to list all the nodes.
 Here, our required disk is “/dev/sdb” which is of 3.7 GiB.
sudo fdisk -l
2. Un-mounting the USB drive’s partition
Un-mounting the storage drive is necessary before performing the format.
Run the following command, but remember to replace “sdb1″ with your USB
drive’s partition label, and then press Enter. 
sudo umount /dev/sdb1

3. Erasing all the data on the drive (discretionary)


You can erase everything on the drive by entering the following command. But,
remember to supplant “sdb” with your USB drive’s name.
sudo dd if=/dev/zero of=/dev/sdb bs=4k status=progress &&
sync

4. Creating a new partition table


Type in the following command, by replacing “sdb” with your USB drive’s
label, and then press Enter.
sudo fdisk /dev/sdb

Enter “o” for creating an empty partition table.


Enter the option “n” for creating a new partition.

Enter “w” to write the table and exit.

5. Execute the following command for viewing the partition.


lsblk
6. Formatting the new volume created
Enter the following command and press Enter for formatting the drive as ext4.
Remember to, replace “sdb1” with your partition’s label: 
sudo mkfs.vfat /dev/sdb1
7. Verifying the newly created filesystem
Run the following command in the terminal:
sudo file -sL /dev/sdb1

8. Lastly, execute the following command for ejecting the drive when finished.
sudo eject /dev/sdb

Now, We have successfully formatted the USB storage device and have also
created a file system with a partition.
fsck Command
The fsck (File System Consistency Check) Linux utility checks filesystems for
errors or outstanding issues.

The tool is used to fix potential errors and generate reports.

This utility comes by default with Linux distributions.

No specific steps or an installation procedure is required to use fsck. Once


you load the terminal, you are ready to exploit the functionalities of the tool.

When to Use fsck in Linux


The fsck tool can be used in various situations:

 Use fsck to run a filesystem check as preventive maintenance or when


there is an issue with your system.
 One common problem fsck can diagnose is when the system fails to
boot.
 Another one is when you get an input/output error when the files on
your system become corrupt.
 You can also use the fsck utility to check the health of external drives,
such as SD cards or USB flash drives.

Basic fsck Syntax


The basic syntax for the fsck utility follows this pattern:

fsck <options> <filesystem>

In the above example, filesystem  can be a device, a partition, a mount point,


etc.

How to Check and Repair Filesystem


There are a few steps to do before you check and repair your file system.
You need to locate a device and unmount.

View Mounted Disks and Partitions


To view all mounted devices on your system and check disk location, use one
of the available tools in Linux.

One method to locate the disk you want to scan is to list the filesystem disks
with the df command:

df -h

The tool prints the data usage on your system and filesystems. Take note of
the disk you want to check with the fsck command.

To view partitions for your first disk, for example, use the following command:

sudo parted /dev/sda 'print'

sda is how Linux refers to your first SCSI disk. If you have two, the second
would be sdb, and so on.
In our example, we got one result since there was only one partition on this
virtual machine. You will get more results if you have more partitions.

The disk name here is /dev/sda and then the number of partitions is shown in
the Number column. In our case, it is one: sda1.

Unmount the Disk

Before you can run a disk check with fsck, you need to unmount a disk or
partition. If you try to run fsck on a mounted disk or partition, you will get a
warning:

Make sure to run the unmount command:

sudo umount /dev/sdb

Replace /dev/sdb with the device you want to unmount.

Note that you cannot unmount root filesystems. Hence, now fsck can’t be


used on a running machine.

Run fsck to Check for Errors


Now that you unmounted the disk, you can run fsck. To check the second
disk, enter:

sudo fsck /dev/sdb

The above example shows the output for a clean disk. If there are multiple
issues on your disk, a prompt appears for each one where you have to confirm
the action.

The exit code the fsck utility returns is the sum of these states:

Mount the Disk


When you finish checking and repairing a device, mount the disk so you can
use it again.

In our case, we will remount the sdb disk:

mount /dev/sdb

Do a Dry Run with fsck


Before you perform a live check, you can do a test run with fsck. Pass the -
N option to the fsck command to perform a test:
sudo fsck -N /dev/sdb

The output prints what would happen but does not perform any actions.

Fix Detected Errors Automatically with fsck


To try to fix potential problems without getting any prompts, pass the -
y option to fsck.

sudo fsck -y /dev/sdb

This way, you say “yes, try to fix all detected errors” without being prompted
every time.

If no errors are found, the output looks the same as without the -y option.

Skip Repair but Print fsck Errors in the Output


Use the -n option if you want to check potential error on a file system without
repairing them.

We have a second drive sdb with some journaling errors. The -n flag prints the


error without fixing it:

sudo fsck -n /dev/sdb

Force fsck to Do a Filesystem Check


When you perform a fsck on a clean device, the tool skips the filesystem
check. If you want to force the filesystem check, use the -f option.

For example:

sudo fsck -f /dev/sdb

The scan will perform all five checks to search for corruptions even when it
thinks there are no issues.

Run fsck on All Filesystems at Once


If you want to perform a check on all filesystems with fsck in one go, pass
the -A flag. This option will go through the etc/fstab  file in one run.

Since root filesystems can’t be unmounted on a running machine, add the -


R option to skip them:

fsck -AR

To avoid the prompts, add the -y option we talked about.

Skip fsck on a Specific Filesystem


If you want fsck to skip checking a filesystem, you need to add -t and “no”
before a filesystem.

For example, to skip ext3 filesystem, run this command:


sudo fsck -AR -t noext3 -y

We added -y to skip the prompts.

Skip Fsck on Mounted Filesystems


To make sure you do not try to run fsck on a mounted filesystem, add the -
M option. This flag tells the fsck tool to skip any mounted filesystems.

To show you the difference, we will run fsck on sdb while it is mounted, and
then when we unmount it.

sudo fsck -M /dev/sdb

While sdb is mounted, the tool exits without running a check. Then, we


unmount sdb and run the same command again. This time, fsck checks the
disk and reports it as clean, or with errors.

Note: To remove the first title line of the fsck tool “fsck from util-linux 2.31.1”
use the -T option.

Run fsck on Linux Root Partition


As we already mentioned, fsck cannot check root partitions on a running
machine since they are mounted and in use.
However, even Linux root partitions can be checked if you boot into recovery
mode and run the fsck check:

1. To do so, power on or reboot your machine through the GUI or by using the
terminal:

sudo reboot

2. Press and hold the shift key during boot-up. The GNU GRUB menu appears.

3. Select Advanced options for Ubuntu.

4. Then, select the entry with (recovery mode) at the end. Let the system load
into the Recovery Menu.

5. Select fsck from the menu.


6. Confirm by selecting <Yes> at the prompt.

7. Once finished, select resume at the recovery menu to boot up the machine.


What if fsck is Interrupted?
You should not interrupt the fsck tool while it is in progress. However, if the
process is interrupted, fsck will finish the ongoing check and then stop.

In case the utility found an error while the check was in process, it will not try
to fix anything if interrupted. You can rerun the check next time and let it
finish.

fsck Linux Command Options Summary


To wrap up, below is the list of the options you can use with the fsck Linux
utility.

Option Description

Try to repair filesystem errors automatically. There will be no prompts, so use it with
-a
caution. 

-A Check all filesystems listed in /etc/fstab.

-C Show progress for ext2 and ext3 filesystems. 

-f Force fsck to check a filesystem. The tool checks even when the filesystem appears to
Option Description

be clean.

Lock the device to prevent other programs from using the partition during the scan
-l
and repair. 

Do not check mounted filesystems. The tool returns an exit code 0 when a filesystem
-M
is mounted.

Do a dry run. The output prints what the fsck would do without executing any actions.
-N
The warning or error messages are printed as well.  

Use to run a scan on multiple filesystems in parallel. It can cause issues, depending on
-P
your setup. Use with caution. 

-R Tell the fsck tool not to check the root filesystems when you use the -A option. 

-r Print device statistics. 

Specify which filesystems type(s) to check with fsck. Consult the man page for
-t
detailed information. 

-T Hide the title when the tool starts. 

-y Try to repair filesystem errors automatically during the check. 

-V Verbose output. 

mount command in Linux


All files in a Linux filesystem are arranged in form of a big tree rooted at ‘/‘.
These files can be spread out on various devices based on your partition table,
initially your parent directory is mounted(i.e attached) to this tree at ‘/‘, others
can be mounted manually using GUI interface(if available) or
using mount command.

mount command is used to mount the filesystem found on a device to big tree


structure(Linux filesystem) rooted at ‘/‘.
Conversely, another command umount can be used to detach these devices
from the Tree.

Syntax:
mount -t type device dir
Other forms:
mount [-l|-h|-V]
mount -a [-fFnrsvw] [-t fstype] [-O optlist]
mount [-fnrsvw] [-o options] device|dir
mount [-fnrsvw] [-t fstype] [-o options] device dir
These commands tells the Kernel to attach the filesystem found at device to
the dir.
Note:
 If you leave the dir part of syntax it looks for a mount point in /etc/fstab.
 You can use –source or –target to avoid ambivalent interpretation.
mount --target /mountpoint
 /etc/fstab usually contains information about which device is need to be
mounted where.
 Most of the devices are indicated by files like /dev/sda4, etc. But it can be
different for certain filesystems

Some Important Options:


 l : Lists all the file systems mounted yet.
 h : Displays options for command.
 V : Displays the version information.
 a : Mounts all devices described at /etc/fstab.
 t : Type of filesystem device uses.
 T : Describes an alternative fstab file.
 r : Read-only mode mounted.
Examples:
 Displays information about file systems mounted:
 Mounts file systems:

 Displays version information:

 Unmounts file systems:

 Bash Startup Files


Invoked as an interactive login shell, or with --login

When Bash is invoked as an interactive login shell, or as a non-interactive shell


with the --login option, it first reads and executes commands from the
file /etc/profile, if that file exists.
After reading that file, it looks for ~/.bash_profile, ~/.bash_login,
and ~/.profile, in that order, and reads and executes commands from the
first one that exists and is readable.

The --noprofile option may be used when the shell is started to inhibit this


behavior.

When an interactive login shell exits, or a non-interactive login shell executes


the exit builtin command, Bash reads and executes commands from the
file ~/.bash_logout, if it exists.

Invoked as an interactive non-login shell

When an interactive shell that is not a login shell is started, Bash reads and
executes commands from ~/.bashrc, if that file exists. This may be inhibited
by using the --norc option. The --rcfile file option will force Bash to
read and execute commands from file instead of ~/.bashrc.

So, typically, your ~/.bash_profile contains the line

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

after (or before) any login-specific initializations.

Invoked non-interactively

When Bash is started non-interactively, to run a shell script, for example, it


looks for the variable BASH_ENV in the environment, expands its value if it
appears there, and uses the expanded value as the name of a file to read and
execute. Bash behaves as if the following command were executed:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the filename.

As noted above, if a non-interactive shell is invoked with the --login option,


Bash attempts to read and execute commands from the login shell startup files.

Invoked with name  sh


If Bash is invoked with the name sh, it tries to mimic the startup behavior of
historical versions of sh as closely as possible, while conforming to
the POSIX standard as well.
When invoked as an interactive login shell, or as a non-interactive shell with
the --login option, it first attempts to read and execute commands
from /etc/profile and ~/.profile, in that order. The --
noprofile option may be used to inhibit this behavior. When invoked as an
interactive shell with the name sh, Bash looks for the variable ENV, expands its
value if it is defined, and uses the expanded value as the name of a file to read
and execute. Since a shell invoked as sh does not attempt to read and execute
commands from any other startup files, the --rcfile option has no effect. A
non-interactive shell invoked with the name sh does not attempt to read any
other startup files.
When invoked as sh, Bash enters POSIX mode after the startup files are read.

Invoked in  POSIX mode

When Bash is started in POSIX mode, as with the --posix command line


option, it follows the POSIX standard for startup files. In this mode, interactive
shells expand the ENV variable and commands are read and executed from the
file whose name is the expanded value. No other startup files are read.

Invoked by remote shell daemon

Bash attempts to determine when it is being run with its standard input
connected to a network connection, as when executed by the remote shell
daemon, usually rshd, or the secure shell daemon sshd. If Bash determines it is
being run in this fashion, it reads and executes commands from ~/.bashrc, if
that file exists and is readable. It will not do this if invoked as sh. The --
norc option may be used to inhibit this behavior, and the --rcfile option
may be used to force another file to be read, but neither rshd nor sshd generally
invoke the shell with those options or allow them to be specified.

Invoked with unequal effective and real  UID/GIDs

If Bash is started with the effective user (group) id not equal to the real user
(group) id, and the -p option is not supplied, no startup files are read, shell
functions are not inherited from the environment,
the SHELLOPTS, BASHOPTS, CDPATH, and GLOBIGNORE variables, if they appear in
the environment, are ignored, and the effective user id is set to the real user id.
If the -p option is supplied at invocation, the startup behavior is the same, but
the effective user id is not reset.
Installing packages

 The APT is the tool, commonly used to install packages, remotely from the
software repository.
 In short it’s a simple command based tool that you use to install
files/softwares.
 Complete command is apt-get and it’s the easiest way to install
files/Softwares packages.
 This easy tools informs you about packages that are currently being installed
and also it informs you about the packages that are available in repositories.

apt-get install ${packagename}
 To remove/uninstall any software, just use remove
 apt-get remove ${packagename}
 The software packages are somewhere in the online repositories, APT handles a
local database on the user’s hard drive that contains informations about the
available packages and where they are located.
 So when the types the command, apt-get install conky, the APT will start finding
the package named conky in the database and will install conky once user types
‘y’ (yes).
 To get the all newly uploaded packages on the repositories, user need to update
APT regularly.
 To update APT database:

 apt-get update
 To update the APT database and also upgrade the security updates and patches
that might be available for some installed softwares, users may do it at once just
by using the commands like this:
 apt-get update; apt-get upgrade

 All of the package management tools, will need user to be in root or


superuser, for example to install software in debian based distributions you
will use apt-get with sudo. Then It will ask you to enter password.

 sudo apt-get install conky


sudo apt-get remove conky
sudo apt-get update
Printer Administration

Linux uses the Common UNIX Printing System, also known as CUPS. CUPS uses


the Internet Printing Protocol (IPP) to allow local printing and print sharing.
The /etc/cups/ directory stores all the configuration files for printing. However, these
files can be easily managed with the Printer Configuration Tool in Linux.

Printers use a description file with one or more driver ("filter") programs that
communicate with the printer through a "backend" program.

CUPS currently uses PPD (PostScript Printer Description) files to describe the printer
and driver programs needed, some of which come with CUPS while others come with
your operating system or Linux distribution.

Backends are specified using a URI (Universal Resource Identifier) where the URI
scheme is the backend name, e.g., "ipp://11.22.33.44/ipp/print" specifies the "ipp"
backend - like PPD files, some backends come with CUPS while others come with
your operating system.

Classes are associated with one or more printers and are typically used to distribute
print jobs amongst a group of printers or provide redundancy or high availability
when printing.

Print jobs sent to a class are forwarded to the next available printer in the class.

Managing Printers
The lpadmin command is used to create, modify, or delete a printer. The -p option specifies
a printer to create or modify:

lpadmin -p printername ...

The lpadmin accepts several additional options after -p printername when adding or
modifying a printer:
-D "description"
Sets the description of the printer which is often shown instead of the printer name, for
example "HP LaserJet".
-E
Enables the printer and accepts new print jobs.
-L "location"
Sets the location of the printer, for example "Conference Room".
-m model
Sets the printer driver using the model name.
-o option=value
Sets the named option.
-v device-uri
Sets the URI for the printer.

The -x option deletes the named printer:

lpadmin -x printername

Printer Drivers and PPDs


The -m option to lpadmin specifies the driver ("model") to use for the printer.
You can run the lpinfo -m command to list all of the available drivers ("models") on your
system:

lpinfo –m

Each line contains the driver name followed by its description, for example:

drv:///sample.drv/dymo.ppd Dymo Label Printer


drv:///sample.drv/epson9.ppd Epson 9-Pin Series
drv:///sample.drv/epson24.ppd Epson 24-Pin Series
drv:///sample.drv/generpcl.ppd Generic PCL Laser Printer
drv:///sample.drv/generic.ppd Generic PostScript Printer
drv:///sample.drv/deskjet.ppd HP DeskJet Series
drv:///sample.drv/laserjet.ppd HP LaserJet Series PCL 4/5
drv:///sample.drv/intelbar.ppd Intellitech IntelliBar Label Printer, 2.1
drv:///sample.drv/okidata9.ppd Oki 9-Pin Series
drv:///sample.drv/okidat24.ppd Oki 24-Pin Series
drv:///sample.drv/zebracpl.ppd Zebra CPCL Label Printer
drv:///sample.drv/zebraep1.ppd Zebra EPL1 Label Printer
drv:///sample.drv/zebraep2.ppd Zebra EPL2 Label Printer
drv:///sample.drv/zebra.ppd Zebra ZPL Label Printer
everywhere IPP Everywhere

The everywhere driver is used for nearly all modern networks printers sold since about
2009. For example, the following command creates a destination for a printer at IP address
11.22.33.44:

lpadmin -p printername -E -v ipp://11.22.33.44/ipp/print -m everywhere

Device URIs (Backends)


CUPS comes with several standard backends that communicate with printers:
dnssd: The Bonjour (DNS-SD) protocol.
ipp: The Internet Printing Protocol (IPP) with optional encryption.
ipps: The Internet Printing Protocol with mandatory encryption.
lpd: The Line Printer Daemon protocol.
socket: The AppSocket (JetDirect) protocol.
usb: The Universal Serial Bus (USB) printer class.
Run the lpinfo -v command to list the available backends and printers:
lpinfo -v
Each line contains the backend "class" followed by the backend name or a full printer device
URI, for example:
network lpd
network ipps
network ipp
network socket
network dnssd://Acme%20Laser%20Pro._ipp._tcp.local./?uuid=545253fb-1cb7-4d8d-98ed-
ab6cd607cea7
network dnssd://Bar99._printer.tcp.local./?uuid=f9efff58-9086-4c95-accb-81dee876a475
network dnssd://Example%20EX-42._ipps._tcp.local./?uuid=4a0c67ad-2824-4ddf-9115-
7d4226c5fe65
network dnssd://Foo%20Fighter-1969._pdl-datastream._tcp.local./?uuid=4e216bea-c3de-
4f65-a710-c99e11c80d2b
direct usb://ZP/LazerJet%20MFP?serial=42
The network class of backends is used for all network protocols.
The direct class of backends is used for directly-connected printers such as USB and
Bluetooth.
Because these backends use a system-specific identifier, you should only use the reported
device URIs.
Once you know the correct URI for the printer, set it using the lpadmin command's -v option:
lpadmin -p printername -v device-uri

Printer Options

The lpadmin command allows you to set various options for a printer:

-o cupsIPPSupplies=false
Turns off IPP supply level reporting for a printer.

-o cupsSNMPSupplies=false
Turns off SNMP supply level reporting for a printer.

-o name=value
Sets the default value for the named PPD option. For example, -o PageSize=Legal sets the
default page size to US Legal.

-o printer-error-policy=name
Sets the policy for errors such as printers that cannot be found or accessed, don't support the
format being printed, fail during submission of the print data, or cause one or more filters to
crash:

abort-job
Aborts the job on error.
retry-job
Retries the job at a future time

retry-current-job
Retries the current job immediately.

stop-printer
Stops the printer on error.

-o printer-is-shared=true/false
Enables/disables per-printer sharing.

-o printer-op-policy=name
Sets the operation policy associated with the printer.

-u allow:{user|@group}{,user|,@group}*

-u allow:all

-u deny:{user|@group}{,user|,@group}*

-u deny:none
Sets user-level access control for the printer. The allow: list defines a whitelist of users and
groups while the deny: list defines a blacklist of users and groups.

Printer Sharing
CUPS supports sharing of printers with other computers and mobile devices.
Two cupsctl options control the general printer sharing features:

--share-printers
Enables sharing of printers with other computers and mobile devices on your local network.

--remote-any
Expands printer sharing to any network that can reach your server.

Once you have enabled printer sharing, you then must select which printers will be shared
using the lpadmin command and the -o printer-is-shared=true option.

For example, to share two printers ("foo" and "bar") on the local network, run the following
commands:

cupsctl --share-printers
lpadmin -p foo -o printer-is-shared=true
lpadmin -p bar -o printer-is-shared=true

Managing Classes
The lpadmin command is used to create, modify, or delete a class.
The -c option specifies a class to create or modify and is combined with the -p option:

lpadmin -p printername -c classname


The -r option specifies that the named printer is removed from the class:

lpadmin -p printername -r classname

The -x option deletes the named class:

lpadmin -x classname

Debug Logging and Troubleshooting

The printing system log files track the activity of the scheduler, printer drivers, and backends.
If problems occur and the log files do not provide sufficient details to diagnose the problem, you
can enable debug logging using the cupsctl command:

cupsctl --debug-logging

To disable debug logging, run the same command with the --no-debug-logging option:

cupsctl --no-debug-logging

Printer administration using GUI BASED TOOL:


https://www.computernetworkingnotes.com/linux-tutorials/how-to-configure-printer-server-in-
linux.html#:~:text=Before%20you%20can%20use%20any,command%20system%2Dconfig
%2Dprinter.

Samba for sharing files and printers


Introduction
Samba is a service in Unix like operating systems which can be used to share
folders across a Windows Network.

Samba is a standard service among almost all the Linux distributions.

Samba can perform the following operations.

1. Act as file server among Windows and Linux machines


2. Act as a printer sharing service
3. Act as a domain controller for a Windows network
4. Act as a client under a Windows domain

Details
Samba Port No 445
Folders related to Samba /etc/samba /usr/lib/samba /usr/share/doc/samba-
x.x.x /usr/log/samba
Samba Configuration file /etc/samba/smb.conf
Starting, stopping and restarting /etc/init.d/smb {start | stop | restart} (Red hat,
Samba server Debian,SUSE)
/etc/init.d/samba {start | stop | restart} (Ubuntu)
File-system CIFS
Driver file /sbin/mount.cifs
Kernel Module cifs.ko
GUI Configuration tool System-config-samba ( Red hat, Ubuntu)
Web Configuration tool SWAT
SWAT Port No 901
Service Part of xinetd or inetd
Swat documents folder /usr/share/swat

Installation
Samba can be installed using the following commands.

For installing Samba on a Ubuntu or Debian  machine, use the following


command:

$ sudo apt-get install samba

For installing Samba on a Fedora or any other Redhat based machine, use
the following command:

$ yum install samba

If you want to install Samba from a source package, you can download it
from the following link:

http://samba.org/samba/download/

Installing system-config-samba
system-config-samba is a GUI tool which is used to configure Samba server
in a Linux machine with GUI.

You can install it by using the appropriate commands below.

$ yum install system-config-samba (for Redhat based)

$ sudo apt-get install system-config-samba (for Debian based)

SWAT
SWAT is web based configuration tool which helps to configure the Samba
server from a remote location.
It is often used to configure complex smb.conf files.
SWAT uses port no 901 to access the Samba server.
Installation
SWAT can be installed on a Redhat based OS using the following command:

$ yum install samba-swat


For a Debian based system the command would be as follows:

$ sudo apt-get install swat

Configuration of Samba using SWAT


Open a browser in a remote or local machine and enter the following address
in the address bar

http://<ip-address of the samba server>:901

Now you can browse through the page to configure various options such as
adding shares and adding printers.

User Management in Samba


Using command line
For authentication, Samba uses a separate set of users that differ from the
Linux users.

Hence we need to create Samba users for accessing the shares from a Samba
server.

To create  a Samba user the following command can be used:

$ smbpasswd -a  <username>


To delete a Samba user you can use the following command

$ smbpasswd -x  <username>


Adding Samba users using system-config-samba
Use the following steps to add users

 Goto Gnome menu-> System -> Administration-> Samba.


 A window opens, click preferences-> Samba users.
 Another Window opens, click add user.
 Another window opens, Choose the Relevant Linux username from “UNIX
username” Dropdown menu, Enter the Samba username as it would be used
in a client machine.
 Enter the password and enter it again to confirm.
 Click “OK”.
You can find the screenshots below
Sharing Folders
Sharing folders using command line
The configuration file for Samba is /etc/samba/smb.conf.
For sharing a folder in Samba you can append the following lines to the file.
[<share-name>]
path =<share-path>
Browseable = yes
Guest ok = yes
read only = no
Valid users = <user1>,<user2>

Restart the Samba service by using the following command:

$ sudo /etc/init.d/samba restart

Sharing folders using system-config-samba


The sharing can also be done using the GUI toot. You can share the folders
using the following procedure:

 Goto Gnome menu-> System-> Administration-> Samba


 A window opens, Click on “Add  Share”
 Another Window opens, In the “Basic” Tab enter the directory path, share
name and Description about the share.
 Choose whether the Share should be writable using the check box
 You can also choose whether the share should be visible while browsing.
 At the tab named “access” , click on “Only allow access to specific users”
and check the user’s name for whom the access needs to be provided.
 Otherwise click on “Allow access to everyone” to allow access to everyone.
You can find the screenshots below.
 

 
Accessing the Samba share from a Windows Client
Accessing the Samba share directly
 Goto Start menu -> Run
 Enter the ip-address of the Samba server.
 Now a Windows explorer will open showing the shared folders from the
Samba server
 Now goto the folder showing with which it has been shared in the server
If you want to browse through the network
Goto Start Menu -> Computer, A window will open, Click on Network. It
shows all the network computers, including your Samba server, connected to
your PC. Now you can browse through the network.

To mount the share every time Windows boots, use the


following steps:
 Click on Start Menu.
 Right click on My Computer and click Map Network Drive.
 A Window will open, Choose a Drive letter and mention the path in
“Folder” in /<ip-address>/ format.
 Check the box “Reconnect at logon”.
 If you want to enter the login credentials of the Samba server click on
“Connect using a different User name” and enter the user-name and
password.
 Click Finish.
Accessing the Samba share from a Linux machine
with Gnome
Accessing the Samba share directly
 Goto Gnome menu-> Places -> Connect to server.
 A window will open. Choose “Service type” as Windows share.
 Enter the server’s Ip-address at the “Server” tab.
 Share name of the folder at the “Share” tab.
 Enter the Username.
 Enter the domain name.
 Click “Connect”.
 Enter the password and click “Connect”.
You can view the screenshots below

 
If you want to browse through the network
 Goto Gnome menu-> Places -> Network
 A windows will open up showing “Windows Network”
 Double click on “Windows Network” to browse through the windows
network which contains Samba servers also
 Click on the Samba server by identifying using the hostname in the list
To mount the share using Command line interface
Use the following command:
$ sudo mount -t cifs /<ip-address>/<share-
name>/  /<mount-point> -o user=<username>
To mount the share at every boot
Add the following line to the /etc/fstab file

//<ip-address>/<share-name>   /<mount-point>   cifs  


user=<username>,password=<password>   0 0
Sharing printers
Sharing through command line
[ printers]
comment = All Printers
path = /var/spool/samba
browseable = yes
printable = yes

Restart the Samba service by using the following command:

$ sudo /etc/init.d/samba restart

Configuring the shared printer on a Windows Client:


 Goto Start menu-> Printers and faxes -> Add a printer.
 A window will open, click next.
 Select “A network printer, or a printer attached to another computer” and
click next.
 Select “Connect to this printer (or to browse for a printer, select this
option and click next)”
 Enter \\< ip-address >\<printer name as in Linux machine> and click
next.
 It will connect to the printer and may say that the driver is not installed (if
driver is present in Windows xp it will proceed without driver installation).
 Install the drivers.
 It will prompt “Do you want to this printer as the default printer?”. Select
your choice an click next.
 Click finish.
Configuring the shared printer on a Linux Client with
Gnome:
 Go to Gnome menu-> System-> Administration-> Printing.
 A window will open, Click new.
 Another Window will open. At devices, drop down Network printer, Click
“Windows Printer via Samba”.
 At the right hand side, There will be a box with ‘smb://’. Here enter the
ip-address and the printer name as  “smb:///”
 Choose the driver and finish the installation.

Logging in Samba
Logs related to Samba can be found in the folder /var/log/samba.

When we try to access the Samba share from another machine it creates a
new file with the file name in the following format.

/var/log/samba/log.<hostname>

Associated services
Some useful commands related to Samba
findsmb
findsmd can be used to find the machines in the network which respond to
smb queries.

testparm
testparm command can be used to test the Samba configuration in the
server.

smbtree
This command can be used to list all the Samba and Windows file servers in
the network.

https://cssoss.wordpress.com/2010/05/25/samba-sharing/#:~:text=Configuring%20the
%20shared%20printer%20on%20a%20Linux%20Client%20with%20Gnome,
%E2%80%9CWindows%20Printer%20via%20Samba%E2%80%9D.

You might also like