Printer of Kali Linux
Backgroud
Because I was the first time to use the HP Laser Jet 1020 printer on Kali Linux. At first I thought it was easy, but i got stuck on the plugin hplip-3.20.2-plugin.run
. Without it, the printer cannot be used normally.
Currently the latest driver version number is 3.20.2, so the version numbers in the following driver names default to this.
Installation
Because Kali Linux is not on the list of systems supported by HP, even if Kali is a secondary development based on Debian. So when we download and install the latest driver from HP’s official website, we will not be able to install it because the system lacks a lot of dependent libraries.
Here we download the driver from Kali‘s official repository.
1 | :~$ sudo apt-get install hplip printer-driver-hpcups cups |
CUPS is the standards-based, open source printing system developed by Apple Inc. for macOS® and other UNIX®-like operating systems.
hd-setup
to download the hplip-3.20.2-plugin.run
plugin.
The program is downloaded from the official Linux repository by default. The Kali‘s official repository does not have this plug-in. so we need to run this command in terminal to obtain the download address of this file on the HP website.
1 | :~$ hp-setup |
Although the final installation fails, but it leaves something similar https://developers.hp.com/sites/default/files/hplip-3.20.2-plugin.run
address on the terminal.
At this time we need to download this file manually.
1 | :~$ wget https://developers.hp.com/sites/default/files/hplip-3.20.2-plugin.run |
Or download from my share 189-cloud, Access Code: dl1s
hplip-3.20.2-plugin.run.asc
is a signature file of HP for hplip-3.20.2-plugin.run
. Without it, an illegal plugin will be prompted when installing this plugin.
Run hp-setup
again and manually select the plugin we just downloaded during the installation process.
Add Printer
Using the graphical interface
- Method One:Search for the printer settings in the control panel and add them in it. This method has the same effect as using CUPS below.
- Method 2: Install
hplip-gui
to run the graphical management interface of the HP printer.Note: Printers added using1
:~$ sudo apt-get install hplip-gui
hplip-gui
can only be used in the hplip-gui program.
Use CUPS
- First, Open
cups.service
1
2
3:~$ sudo systemctl start cups.service
:~$ sudo netstat -anpl | grep cups
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 140391/cupsd - We can see that
cupsd
has opened the local port 631, so we can use the browser to open it.1
:~$ firefox 127.0.0.1:631
Administration
: This menu is an administrator page where you can add/find/manage/configure printers.Note :The default user name of this page is root, and the password is the root password of this machine. Jobs
: This menu displays a list of printer, such as completed/unfinished print jobs.Printers
:This menu shows the printers that have been added to the current CUPS.
At this point, the local HP printer is ready to use.
Using CUPS is the same as using the control panel to add a printer.
Configure File
The configuration file for CUPS is located at /etc/cups/cupsd.conf
.
You can modify the configuration file under the Administrator menu of the Web management, or use vim
to modify directly in the terminal.
cupsd.conf
:
1 | # Only listen for connections from the local machine. |
cups Shared Printer
Change the listening address of CUPS to 0.0.0.0.
1 | :~$ vim /etc/cups/cupsd.conf |
At this time, under Linux/Mac PC with CUPS installed, or under iPhone / Android 7+, simply search for the printer. If not found, you can manually select the ipps
network protocol and enter the IP address of the PC where the printer is located, such as https://192.168.1.2:631/
.
Android has built-in print services since 7.0. If the version is lower than 7.0, please install print services by yourself.
Share Printer with Samba
The HP Laser Jet 1020 printer does not support networking, so Samba is used here to share this printer.
Why use Samba for sharing? Because it is compatible with windows.
If you only share printers between Mac/Linux/iPhone/Android, you can use CUPS directly.
When using the CUPS print server back end, Samba must have been built with CUPS support enabled.
To verify, enter:
1 | :~$ smbd -b | grep "HAVE_CUPS" |
If no output is displayed:
- Samba was built using the
--disable-cups
parameter. - The Samba configure script was unable to locate the required libraries for CUPS support. For details, see Package Dependencies Required to Build Samba.
CUPS
To add a raw printer to an CUPS print server:
- Open the CUPS admin web interface in your browser. For example,
https://servername:631/admin
- Select the
Administration
tab and clickAdd Printer
. - Select the connection type and enter the corresponding URL to the printer’s queue or to the remote print server queue. For example:
- LPD-based printers:
lpd://printer_name/queue
. - IPP (Internet Printing Protocol)-based printers:
ipp://printer_name/ipp/port
. - SMB (Server Message Block)-based printers:
smb://username:password@domain/windows_print_server_host_name/printer_name
Note that forwarding a job to a print server running Windows Vista or newer, or Windows Server 2008 or newer requires authentication. - Enter a name for the printer. This name is used in the
smb.conf
when sharing the printer using Samba. - Select the Raw printer vendor and model.
- Save the settings.
smb.conf
Divided into anonymous sharing and password verification sharing.
1. Enabling the spoolssd Service
The Samba spoolssd
is a service that is integrated into the smbd
service. If you configured Samba as a print server, you can additionally enable spoolssd
to increase performance on print servers with a high number of jobs or printers.
Without spoolssd
, Samba forks the smbd
process or each print job and initializes the printcap cache. In case of a large number of printers, the smbd
service can become unresponsive for multiple seconds when initializing the cache. The spoolssd
service enables you to start pre-forked smbd
processes that are processing print jobs without any delay. The main spoolssd
smbd
process uses a low amount of memory, and forks and terminates child processes
To enable the spoolssd
service:
- Edit the
[global]
section in yoursmb.conf
file: - Add the following parameters:
1
2
3
4[global]
...
rpc_server:spoolss = external
rpc_daemon:spoolssd = fork - Optionally, you can set the following parameters:
Parameter Default Description spoolssd:prefork_min_children 5 Minimum number of child processes poolssd:prefork_max_children 25 Maximum number of child processes spoolssd:prefork_spawn_rate 5 Samba forks this number of new child processes, up to the value set in spoolssd:prefork_max_children, if a new connection is established spoolssd:prefork_max_allowed_clients 100 Number of clients, a child process serves spoolssd:prefork_child_min_life 60 Minimum lifetime of a child process in seconds. 60 seconds is the minimum. - Restart Samba.
1
:~$ sudo smbcontrol all reload-config
After the restart, Samba automatically starts smbd sub-processes:
1 | :~$ ps axf |
2. Enabling the Print Server Support in Samba
To enable the print server support:
- Set the printing back end in the printing parameter of the
[global]
section in yoursmb.conf
file. For example:1
2
3[global]
...
printing = cups - Add the following section to your
smb.conf
:1
2
3[printers]
path = /var/spool/samba/
printable = yes - Create the spool directory set in the path parameter:
1
2:~$ mkdir -p /var/spool/samba/
:~$ chmod 777 /var/spool/samba/ - Reload Samba:
1
:~$ sudo smbcontrol all reload-config
3. Sharing a Printer
Automatic and anonymous Sharing of All Printers Configured in the Print Server Back End
Using the default setting, all printers configured in the print server back end are automatically shared.
- Modify the flollowing parameter to the
[printers]
section of oursmb.conf
file:1
2
3
4
5
6
7
8[printers]
comment = All Printers
browseable = yes
path = /var/spool/samba
printable = yes
guest ok = yes
read only = yes
create mask = 0700 - Reload Samba:At this point, all clients on the same network segment can use the printer.
1
:~$ sudo smbcontrol all reload-config
Anonymous sharing is automatically performed whenever a Samba host adds another printer.
Sharing a printer with a password
Disabling the Automatic Printer Sharing
To disable the automatic printer sharing:
- Add the following parameter to the
[global]
section of yoursmb.conf
file:1
2
3[global]
...
load printers = no - Reload Samba
1
:~$ sudo smbcontrol all reload-config
Manual Sharing of Printers
To manually share a printer:
- Verify that the automatic printer sharing is disabled. See Disabling the Automatic Printer Sharing.
- Add the share for the printer to your
smb.conf
file:Set the1
2
3
4
5
6
7
8
9
10[hp1020]
path = /var/spool/samba/
printable = yes
printer name = HP-LaserJet-1020
user client driver = no
guest ok = no
writable = no
write list = root
valid users = @sambaprinter name
parameter to the name of the printer used in the local print server back end. - Reload Samba
1
:~$ sudo smbcontrol all reload-config
At this point, we can use the password to log in and use the printer on other clients on the same network segment.