0%

Printer of Kali Linux

Lguna

I am using HP printer (HP Laser Jet 1020) on linux at the first time, and here is a record of the installation process.

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.

The print driver has not been installed at this time.We also need to use the 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
2
:~$ wget https://developers.hp.com/sites/default/files/hplip-3.20.2-plugin.run
:~$ wget https://developers.hp.com/sites/default/files/hplip-3.20.2-plugin.run.asc

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.

At this point, the installation of the HP printer driver is complete.

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.
    1
    :~$ sudo apt-get install hplip-gui
    Note: Printers added using 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
    Web Manage Page
    • 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Only listen for connections from the local machine.
Listen 127.0.0.1:631
...
# Restrict access to the server.
# The following rule only allows 127.0.0.1 to access the web management page
<Location />
Order deny,allow
Deny From All
Allow From 127.0.0.1
</Location>

# Restrict access to the admin pages
# Only allow 127.0.0.1 to access admin pages
<Location /admin>
Order allow,deny
Allow From 127.0.0.1
Deny From All
</Location>

cups Shared Printer

Change the listening address of CUPS to 0.0.0.0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
:~$ vim /etc/cups/cupsd.conf
...
Listen 0.0.0.0:631
...
# only allow 127.0.0.1 and 192.168.1.0/24 to access web page
<Location />
Order deny,allow
Deny From All
Allow From 127.0.0.1
Allow From 192.168.1.*
</Location>

# only allow 127.0.0.1 and 192.168.1.2 to access admin pages
<Location /admin>
Order allow,deny
Allow From 127.0.0.1
Allow From 192.168.1.2
Deny From All
</Location>
:~$ sudo systemctl restart cupsd.service

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
2
3
4
:~$ smbd -b | grep "HAVE_CUPS"
HAVE_CUPS_CUPS_H
HAVE_CUPS_LANGUAGE_H
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 click Add 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:[email protected]/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 your smb.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
2
3
4
5
6
7
:~$ ps axf
...
30903 smbd
30912 \_ smbd
30913 \_ smbd
30914 \_ smbd
30915 \_ smbd

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 your smb.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 our smb.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:
    1
    :~$ sudo smbcontrol all reload-config
    At this point, all clients on the same network segment can use the printer.
    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 your smb.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:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    [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 = @samba
    Set the printer 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.

---- The End Thanks ----
Donate if you like the article.