[Solved] how to install a printer directly connected to dietpi (via USB)

Hi again to everybody,
I would like to install a HP Deskjet 2540, directly connected through USB to the Dietpi.
How can I do it?
I would like it will be also the printer I can use from all the devices in the network.
is it possible?

Have a look to our online docs. There we have a print software section. Maybe CUPS could be an option https://dietpi.com/docs/software/printing/#cups

Your printer has official linux drivers from HP and supports printing via network. The package is available via offical Debian / Raspberry Pi repositories.
There is even a good documentation on the HP webiste:

https://developers.hp.com/hp-linux-imaging-and-printing/KnowledgeBase/How-To's
https://developers.hp.com/hp-linux-imaging-and-printing/install/step4/cups/net


sudo apt
sudo apt install hplip hplip-gui
sudo usermod -a -G lpadmin pi

HPLIP would also install cups and some other dependencies. I don’t know what happens (config-wise) when you first install cups via dietpi-software and afterwards HPLIP.

I tried to follow the steps suggested but after the installation when I launch: sudo usermod -a -G lpadmin pi
it says me: usermod: user ‘pi’ does not exist

I’ve also checked this page: https://dietpi.com/docs/software/printing/#cups and even if it is dedicated only to CUPS (which maybe could be the right instrument for me) it doesn’t tell me how to install it. I mean which command should I use to install it?

Of course the user pi did not exist on DietPi. Therefore the command is failing and not necessary. Just got to dietpi-software and install CUPS.

I’ve installed CUPS and looks like it’s done.
But when I try to reach CUPS through the browser with this address: http://192.168.1.15:631 as suggested it doesn’t work.I’ve tried also with /admin… just in case :slight_smile: .
how can I check if everything went well?

you can check following.

systemctl status cups
journalctl -u cups
ss -tulpn | grep LISTEN

Just out of curiosity. There is no firewall running which could block the access?

I’m not sure if pi-hole could be considered a firewall… is it? In case I’ll open a new topic soon :wink:

I tried to launch all these commands and this is the result:

systemctl status cups
● cups.service - CUPS Scheduler
     Loaded: loaded (/lib/systemd/system/cups.service; disabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-02-14 01:36:14 CET; 7h ago
TriggeredBy: ● cups.socket
       Docs: man:cupsd(8)
   Main PID: 10231 (cupsd)
     Status: "Scheduler is running..."
      Tasks: 1 (limit: 415)
        CPU: 145ms
     CGroup: /system.slice/cups.service
             └─10231 /usr/sbin/cupsd -l

Feb 14 01:36:13 DietPi systemd[1]: Starting CUPS Scheduler...
Feb 14 01:36:14 DietPi systemd[1]: Started CUPS Scheduler.
root@DietPi:~# journalctl -u cups
-- Journal begins at Sun 2022-02-13 20:59:54 CET, ends at Mon 2022-02-14 08:51:08 CET. --
Feb 14 01:27:05 DietPi systemd[1]: Stopping CUPS Scheduler...
Feb 14 01:27:05 DietPi systemd[1]: cups.service: Succeeded.
Feb 14 01:27:05 DietPi systemd[1]: Stopped CUPS Scheduler.
Feb 14 01:36:13 DietPi systemd[1]: Starting CUPS Scheduler...
Feb 14 01:36:14 DietPi systemd[1]: Started CUPS Scheduler.
root@DietPi:~# ss -tulpn | grep LISTEN
tcp   LISTEN 0      80         127.0.0.1:3306       0.0.0.0:*    users:(("mariadbd",pid=10150,fd=17))                    
tcp   LISTEN 0      511        127.0.0.1:6379       0.0.0.0:*    users:(("redis-server",pid=10094,fd=7))                 
tcp   LISTEN 0      4096         0.0.0.0:111        0.0.0.0:*    users:(("rpcbind",pid=371,fd=4),("systemd",pid=1,fd=76))
tcp   LISTEN 0      1024         0.0.0.0:80         0.0.0.0:*    users:(("lighttpd",pid=10227,fd=4))                     
tcp   LISTEN 0      32           0.0.0.0:53         0.0.0.0:*    users:(("pihole-FTL",pid=730,fd=7))                     
tcp   LISTEN 0      1000         0.0.0.0:22         0.0.0.0:*    users:(("dropbear",pid=410,fd=4))                       
tcp   LISTEN 0      128        127.0.0.1:631        0.0.0.0:*    users:(("cupsd",pid=10231,fd=7))                        
tcp   LISTEN 0      256        127.0.0.1:5335       0.0.0.0:*    users:(("unbound",pid=586,fd=4))                        
tcp   LISTEN 0      256        127.0.0.1:8953       0.0.0.0:*    users:(("unbound",pid=586,fd=6))                        
tcp   LISTEN 0      1024         0.0.0.0:443        0.0.0.0:*    users:(("lighttpd",pid=10227,fd=6))                     
tcp   LISTEN 0      5          127.0.0.1:4711       0.0.0.0:*    users:(("pihole-FTL",pid=730,fd=16))                    
tcp   LISTEN 0      511            [::1]:6379          [::]:*    users:(("redis-server",pid=10094,fd=8))                 
tcp   LISTEN 0      4096            [::]:111           [::]:*    users:(("rpcbind",pid=371,fd=6),("systemd",pid=1,fd=78))
tcp   LISTEN 0      1024            [::]:80            [::]:*    users:(("lighttpd",pid=10227,fd=5))                     
tcp   LISTEN 0      32              [::]:53            [::]:*    users:(("pihole-FTL",pid=730,fd=9))                     
tcp   LISTEN 0      1000            [::]:22            [::]:*    users:(("dropbear",pid=410,fd=5))                       
tcp   LISTEN 0      128            [::1]:631           [::]:*    users:(("cupsd",pid=10231,fd=6))                        
tcp   LISTEN 0      256            [::1]:8953          [::]:*    users:(("unbound",pid=586,fd=5))                        
tcp   LISTEN 0      1024            [::]:443           [::]:*    users:(("lighttpd",pid=10227,fd=7))                     
tcp   LISTEN 0      5              [::1]:4711          [::]:*    users:(("pihole-FTL",pid=730,fd=14))                    
root@DietPi:~#

I think is working properly. isn’t it?

If yes, why can’t I reach CUPS from inside my network using port 631 as suggested on this page?

quite simple, CUPS is not LISTEN to the network as it is bound to localhost (127.0.0.1) only.

tcp   LISTEN 0      128        127.0.0.1:631        0.0.0.0:*    users:(("cupsd",pid=10231,fd=7))

Do you used dietpi-software to install CUPS?

can you share your configuration

cat /etc/cups/cupsd.conf | grep Listen

as well pls share the version installed.

dpkg -l cups

Yes I do!
This is the result of the above command:

 root@DietPi:~# cat /etc/cups/cupsd.conf | grep Listen
Listen localhost:631
Listen /run/cups/cups.sock
root@DietPi:~# dpkg -l cups
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/
Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version            Architecture Description
+++-==============-==================-============-==================
=================================================
ii  cups           2.3.3op2-3+deb11u1 armhf        Common UNIX Printi
ng System(tm) - PPD/driver support, web interface
root@DietPi:~#

hm strange. We use the configuration file as it has been provided by the cups apt package. I did a test on 32bit as well as 64bit. In both cases, configuration was correct. Not sure what makes your system again special :thinking:

Try following

G_CONFIG_INJECT 'Listen localhost:' 'Listen 0.0.0.0:631' /etc/cups/cupsd.conf
systemctl restart cups
ss -tulpn | grep LISTEN

Should be LISTEN to 0.0.0.0 now

That’s right, now it is LISTEN to 0.0.0.0
but when I try to reach the CUPS from the browser, now it says me: 404 Not Found before was different :wink:

what is the URL you try to reach CUPS on? Error 404 would mean the CUPS own web server (service) is working but the specific web side could not be displayed. Honestly I even don’t know how this should be possible, as this is all part of the CUPS application themselves. Nothing we influence from our side. Did you tried to reinstall CUPS?

I still haven’t tried to reinstall CUPS.
The address I’m trying to reach from inside my network as suggested here https://dietpi.com/docs/software/printing/#cups is “my dietpi address:631”. https://192.168.1.15:631

Is this the right way to find it?

What about trying to reach the site with plain http instead of https?

I’m not sure, but I’ve tried with both…
As soon as I’ll be back at home I try it again

And one more request. Can you share your configuration file

cat  /etc/cups/cupsd.conf

This is the “long” configuration file:

cat  /etc/cups/cupsd.conf
#
# Configuration file for the CUPS scheduler.  See "man cupsd.conf" for a
# complete description of this file.
#

# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel warn
PageLogFormat

# Specifies the maximum size of the log files before they are rotated.  The value "0" disables log rotation.
MaxLogSize 0

# Default error policy for printers
ErrorPolicy retry-job

# Only listen for connections from the local machine.
Listen 0.0.0.0:631
Listen /run/cups/cups.sock

# Show shared printers on the local network.
Browsing On
BrowseLocalProtocols dnssd

# Default authentication type, when authentication is required...
DefaultAuthType Basic

# Web interface setting...
WebInterface Yes

# Restrict access to the server...
<Location />
  Order allow,deny
</Location>

# Restrict access to the admin pages...
<Location /admin>
  Order allow,deny
</Location>

# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
</Location>

# Restrict access to log files...
<Location /admin/log>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
</Location>

# Set the default printer/job policies...
<Policy default>
  # Job/subscription privacy...
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default

  # Job-related operations must be done by the owner or an administrator...
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    Order deny,allow
  </Limit>

  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  <Limit All>
    Order deny,allow
  </Limit>
</Policy>

# Set the authenticated printer/job policies...
<Policy authenticated>
  # Job/subscription privacy...
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default

  # Job-related operations must be done by the owner or an administrator...
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    AuthType Default
    Order deny,allow
  </Limit>

  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  <Limit All>
    Order deny,allow
  </Limit>
</Policy>

# Set the kerberized printer/job policies...
<Policy kerberos>
  # Job/subscription privacy...
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default

  # Job-related operations must be done by the owner or an administrator...
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    AuthType Negotiate
    Order deny,allow
  </Limit>

  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    AuthType Negotiate
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
    AuthType Negotiate
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  <Limit All>
    Order deny,allow
  </Limit>
</Policy>

with http instead https the system says me:

You cannot access this page.