Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Linux / Printing from Linux to a Windows Shared Printer

May 29, 2024 LinuxWindows 10Windows 11

Printing from Linux to a Windows Shared Printer

This article explains how to connect and print from a Linux computer to a shared printer connected to a Windows host.

  1. 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); Shared printer on Windows print server
  2. Create a new local user winusr1. Remove a user from the local Users group, set the password to never expire, and prevent password changes.
    Create a Windows user that will be used to connect to the shared printer.
    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

smbclient - list available SMB shares and printer on remote Windows computer

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:

$ smbclient -W DOMAIN -U winusr1//192.168.31.94/HPM1530
Print the specified file:
smb: \> print /home/sysops/test.txt
printing file test.txt as test.txt (856,2 kb/s)
smb: \> quit

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:

$ dpkg -l cups
$ dpkg -l system-config-printer
$ systemctl status cups

Now connect a shared network printer from Linux:

  1. Navigate to the following URL in your browser to open the CUPS web interface localhost:631 ;
  2. Go to Administration -> Add printer -> Other network printers -> Windows Printer via SAMBA;
    Add Windows Printer via SAMBA
  3. 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);
    CUPS: shared network printer connection string with Windows user credentials
  4. Then set the printer name and description; CUPS: set printer name and description
  5. 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 lpinfo list available printer drivers on Linux
    Select the driver you found in CUPS.
    Select printer driver
  6. The shared printer installation is complete.
Where can you find CUPS print drivers for Linux? In the case of HP printers, for example, most Linux distributions come with the HP Linux Printing and Imaging System (HPLIP) package pre-installed. It includes drivers for most HP printers.

$ dpkg -l hplip

HP Linux Printing and Imaging System (HPLIP) package

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 first attempt to print a document from Linux to a shared Windows printer failed in my case with an error. Check /var/log/cups/error_log for errors:

E [Job 13] SMB connection failed!
E [Job 13] Unable to connect to CIFS host: NT_STATUS_IO_TIMEOUT

SMB/CIFS printer connection failed: SMB1 protocol

This indicates that CUPS cannot connect to the printer’s SMB folder on the Windows machine. In this case, the problem is that Linux smbclient tries to use SMB 1.0 protocol to access shared printers. The SMB 1.0 version is disabled on Windows 10 and 11, and such a connection will be rejected.

Edit the file /etc/samba/smb.conf to make the Linux SMB client use a more secure SMB 2 or 3 version for connections. In the [global] section, add the following lines:

client min protocol = SMB2
client max protocol = SMB3

Linix: enable SMB2 and SMB3 on samba

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

lpadmin: add smb printer on Linux

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).

Connected CUPS printers in printers.conf

1 comment
5
Facebook Twitter Google + Pinterest
previous post
How to Share USB Scanner Over Network on Windows with NAPS2
next post
How to Assign (Passthrough) a Physical GPU to a Hyper-V Virtual Machine

Related Reading

How to Cancel Windows Update Pending Restart Loop

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Change BIOS from Legacy to UEFI without Reinstalling...

April 21, 2025

Remove ‘Your License isn’t Genuine’ Banner in MS...

April 21, 2025

Uninstalling Windows Updates via CMD/PowerShell

April 18, 2025

1 comment

Stephen May 10, 2025 - 4:49 pm

Didn’t work. I got the point where I enter the command:

smbclient -L \\{windows hostname} -U {user} (replacing the fields with my hostname and user that I created on Windows)

I got the error NT STATUS LOGON FAILURE. Can’t figure out how to solve that.

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Fixing ‘The Network Path Was Not Found’ 0x80070035 Error Code on Windows
  • Recovering Files from BitLocker Encrypted Drive
  • Install Any OS from ISO Image over Network with iVentoy
  • Monitoring Domain Name Expiration Date with Zabbix
  • Turn Linux Computer into Wi-Fi Access Point (Hotspot)
  • Get Started with Docker on Windows (WSL2) without Docker Desktop
  • How to Use Ansible to Manage Windows Machines
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top