This article explains how to connect and print from a Linux computer to a shared printer connected to a Windows host.
- The first step is to share the printer on a Windows computer to which it is connected. Open the printer properties, go to the Sharing tab, enable the Share this printer option, and specify the shared printer name (the name must not contain spaces or special characters).
- Create a new local user winusr1. Remove a user from the local Users group, set the password to never expire, and prevent password changes.
You can use PowerShell to create a local user with the specified settings:
$pass = ConvertTo-SecureString "pass2024W0rd-" -AsPlainText -Force
New-LocalUser -Name winusr1 -Password $pass -PasswordNeverExpires -UserMayNotChangePassword
Remove-LocalGroupMember -Group Users -Member winusr1
By default, the SMB protocol is used to connect shared Windows printers. Install the smbclient to check if the shared printer on the Windows host can be remotely accessed from Linux:
On Ubuntu/Debian run the command:
$ sudo apt install smbclient
List SMB shares on a remote Windows machine
$ smbclient -L \192.168.31.94 -U winusr1
- 192.168.31.94 – IP address or hostname of the Windows computer
- winusr1 – local Windows username
This command lists shared network folders (including administrative shares) and printers.
From the console, you can check the availability of an SMB printer and send a file to print:
<pre>$ smbclient -W DOMAIN -U winusr1//192.168.31.94/HPM1530</pre>
Print the specified file:
<pre>smb: > print /home/sysops/test.txt
printing file test.txt as test.txt (856,2 kb/s)
smb: > quit</pre>
The easiest way to access and manage network printers under Linux is to use the built-in Common UNIX Printing System (CUPS). The system-config-printer web interface is used to manage CUPS.
CUPS and system-config-printer are installed by default on most Linux desktop distros. Check and install if necessary:
<pre>$ dpkg -l cups
$ dpkg -l system-config-printer
$ systemctl status cups</pre>
Now connect a shared network printer from Linux:
- Navigate to the following URL in your browser to open the CUPS web interface
localhost:631
; - Go to Administration -> Add printer -> Other network printers -> Windows Printer via SAMBA;
- Use the following format to specify the shared printer connection settings
smb://winusr1:[email protected]/HPM1530
(This string includes the user name and password, the remote Windows hostname/IP and the shared printer name); - Then set the printer name and description;
- Next, CUPS will ask you to select the printer manufacturer and model. The list of drivers can be quite long. Use the following command to find the driver name by printer model quickly:
$ lpinfo -m| grep 1536
Select the driver you found in CUPS. - The shared printer installation is complete.
$ dpkg -l hplip
You can install the HPLIP package manually:
$ sudo apt install hplip hplip-gui
Other vendors may also release similar driver packages, or you may be able to find a pre-built PPD file for a specific printer. It is also possible to use the foomatic PPD printer driver library (automatically installed on ubuntu-desktop):
$ apt install foomatic-db-compressed-ppds
The initial attempt to send a document for printing from Linux to a printer shared over Windows resulted in an error in my scenario. You can examine the /var/log/cups/error_log to find the errors:
E [Job 13] Failed connection to SMB!E [Job 13] CIFS host connection failed: NT_STATUS_IO_TIMEOUT
Such an error is suggestive of the fact that CUPS (common Unix printing system) is unable to connect with the printer’s SMB folder available on the Windows computer. To elaborate, the issue here is that the Linux smbclient is employing the SMB 1.0 protocol for accessing printers that are shared. Given that the version 1.0 of SMB is not activated on Windows 10 and 11, such a connection will inevitably be declined.
You can resolve this by editing the /etc/samba/smb.conf file, thereby enabling the Linux SMB client to use a safer version of SMB (2 or 3) for establishing connections. You need to insert the following lines under the [global] section:
client min protocol = SMB2client max protocol = SMB3
Restart CUPS:
$ sudo systemctl restart cups
The Linux client can now successfully print to a shared printer on the Windows computer.
You can also connect to a shared Windows printer from the command line. The first step is to find the name of the driver for your printer model:
$ lpinfo --make-and-model '1536' -m
Copy the full name of the driver and connect the SMB printer:
$ sudo lpadmin -p HP1536mfp -v smb://winusr1:[email protected]/HPM1536 -m postscript-hp:0/ppd/hplip/HP/hp-laserjet_m1530_mfp_series-ps.ppd
Enable the CUPS printer on Linux:
$ cupsenable HP1536mfp
List printers:
$ lpsatat -v
$ lpstat -p
The list of connected SMB printers is stored in the /etc/cups/printers.conf file. Note that the Windows username and password you use to connect to the printer are stored here in plain text (so this user must have minimal permissions on the Windows machine).