Печатаем через CUPS
Когда деревья были большими, а трава зеленее… Хотя нет, проще говоря, не успел я купить себе нормальный принтер, который сможет позволить использовать AirPrint дома. Поэтому моему взору открылся CUPS. А учитывая что, на официальном сайте есть очень интересная информация – The standards-based, open source printing system developed by Apple for iOS®, iPadOS®, and macOS®. CUPS uses IPP Everywhere™ to support printing to local and network printers. Были попытки установить CUPS на Docker, но не срослось. Поэтому (учитывая в наличии Raspberry Pi 4 Model B) было принято решение об apt install cups. Но обо всем по порядку 🙂
Малинка – это малинка, а вот ковыряний… В общем, чтобы статья получилась точно из разряда how-to (в моем понимании, скопипастил и работает) пришлось поднять отдельную Ubuntu и пройтись снова по всем шагам!
И так, на чистую Ubuntu начинаем устанавливать и настраивать CUPS.
1 2 3 4 |
apt install cups systemctl start cups systemctl enable cups systemctl status cups |
Проверяем состояние:
root@cups-srv:~# systemctl status cups
● cups.service – CUPS Scheduler
Loaded: loaded (/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-05-14 16:45:14 UTC; 27min ago
TriggeredBy: ● cups.path
● cups.socket
Docs: man:cupsd(8)
Main PID: 3803 (cupsd)
Status: “Scheduler is running…”
Tasks: 2 (limit: 2200)
Memory: 4.3M
CPU: 709ms
CGroup: /system.slice/cups.service
├─3803 /usr/sbin/cupsd -l
└─3973 /usr/lib/cups/notifier/dbus dbus:// “”
Добавляем пользователя (текущего) в группу lpadmin:
1 |
adduser flammlin lpadmin |
В конфигурационном файле открываем доступ к CUPS по порту 631:
1 |
nano /etc/cups/cupsd.conf |
Раскомментируем строчку:
1 2 3 |
# Only listen for connections from the local machine # Listen localhost:631 Port 631 |
Перезапускаем службу и пробуем открыть веб-страницу CUPS.
1 |
systemctl restart cups |
В моем примере, Ubuntu имеет адрес 192.168.0.23, поэтому будем обращаться у нему используя порт 631 – http://192.168.0.23:631/ И конечно же получим ошибку – You cannot access this page. Проблема в том, что в секциях конфигурационного файла мы не разрешили доступ к веб-интерфейсу.
Открываем файл и заменяем одну секцию другой:
1 |
nano /etc/cups/cupsd.conf |
Что необходимо заменить:
1 2 3 4 5 6 7 8 9 |
# Restrict access to the server... <Location /> Order allow,deny </Location> # Restrict access to the admin pages... <Location /admin> Order allow,deny </Location> |
Заменить нужно на:
1 2 3 4 5 6 7 8 9 10 11 |
# Restrict access to the server... <Location /> Order allow,deny Allow 192.168.0.0/24 </Location> # Restrict access to the admin pages... <Location /admin> Order allow,deny Allow 192.168.0.0/24 </Location> |
Дальше необходимо перезапустить службу CUPS и снова открыть страницу с веб-интерфейсом.
1 |
systemctl restart cups |
Если используется встроенный FireWall – то необходимо открыть доступ:
1 2 |
ufw allow in from 192.168.0.0/24 to any port 631 systemctl restart cups |
Так же для правильной работы может потребоваться:
1 2 3 4 |
apt install cups cups-client cups-filters cups-ipp-utils apt install avahi-discover cups cups-pdf apt install hplip systemctl restart cups |
Интересная особенность, при добавлении принтера в веб-интерфейсе – переадресация на https + запрос логина и пароля (вводим от подключения к ssh).
Как видно из примера, принтер (МФУ) используется HP LaserJet M2727. Данное МФУ досталось мне в 2011 году и теперь используется для печати с iOS устройств, что крайне экономит уйму времени.
Есть конечно проблемы при печати больших документов или фотографий, но нажатие кнопки “Дальше” решает проблему.
Итоговый файл cupsd.conf выглядит у меня вот так:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# # 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 localhost:631 Port 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 Allow @local </Location> # Restrict access to the admin pages... <Location /admin> Order allow,deny Allow @local </Location> # Restrict access to configuration files... <Location /admin/conf> AuthType Default Require user @SYSTEM Order allow,deny Allow @local </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> |
На этом все – удачной печати 🙂