前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >打印机+树莓派=网络打印机?

打印机+树莓派=网络打印机?

作者头像
xcsoft
发布2021-07-14 16:38:24
3.3K1
发布2021-07-14 16:38:24
举报
文章被收录于专栏:星辰日记星辰日记星辰日记

前言

  之前买了台pi zero,然后一直仍在家里当网站服务器,感觉有点浪费。正好家里有台打印机,于是找了根OTG线连接打印机实现局域网内共享打印机。

什么是CUPS

  CUPS(Common UNIX Printing System,即通用Unix打印系统)是linux下一款可以创建打印机服务器的软件,内置了常用打印机的驱动,并且配有WEB页面,可以说是一款很棒的软件了。

准备

树莓派*1(此处使用的是raspbian系统)
路由器*1
打印机*1
电脑*1(用于配制树莓派)
一双敢于尝试的双手

开始

  1.将树莓派通电,并连接打印机(打印机应处于开机状态)

开机
开机

  2.电脑连接树莓派SSH.

SSH
SSH

  3.提权,并安装cups(中途需要输入Y回车同意安装).

sudo -s
apt-get install cups

  4.安装完成后将pi添加到Ipadmin如果你使用其他用户登录,则添加你自己的用户名.

sudo usermod -a -G lpadmin pi

  5.接下来,先介入将cups服务停止,然后编辑配置文件(这边推荐使用vim因为习惯了吧).

sudo service cups stop
apt-get install vim
vim /etc/cups/cupsd.conf

  编辑配置内容为:

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

# Deactivate CUPS' internal logrotating, as we provide a better one, especially
# LogLevel debug2 gets usable now
MaxLogSize 0

# Only listen for connections from the local machine.
# Listen localhost:631
# Listen /run/cups/cups.sock
Listen 0.0.0.0:631
...
...
...
# 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 from @Local
</Location>

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

# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow [email protected]
</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>

  TIP:不同版本的cups配置内容应不同,但修改配置主要是为了是局域网内的计算机都能访问到cups server(cups默认只允许本机访问,就是加个显示屏浏览器输入127.0.0.1:631)

  然后,重新启动cups服务.

sudo service cups start

  6.接着浏览器访问http://你的树莓派IP地址:631进入cups的配置界面,可以看到cups还是挺注重用户使用的,制作了网页来方便用户配置吧。在上面菜单栏中找到Administrator点击进入.

cups
cups

  7.进入后点击Printers中的add printer.按照提示访问https://ip:631/admin/,自签证书提示不安全很正常,此处我们点击高级-继续前往ip(不安全)。打开后重新点击add printer,这是提示登录,输入自己第四步添加权限的用户名以及ssh密码即可.

add
add

  8.选择你自己的打印机(本人使用的是Lenovo_M7206)并点击continue

continue
continue

  9.勾选share this printrt 再次点击continue.

share
share

  10.下一页面是用来选择自己打印机驱动的,cups内置了大多数常见的打印机驱动,如果没有你适配的请联系打印机供应商提供linux版本的打印机驱动(由于我的打印机并没有找到驱动,但该打印机驱动是gdi驱动的,所以我就直接使用的同款gdi驱动的brother驱动)选择好后点击add printer

set
set

  11.打印机选项这边直接默认即可,直接点击Set Default Options此时,您已成功配置cups server并连接至打印机了.

windows连接打印机

  1.打开设置,点击设备.

dervice
dervice

  2.选择打印机和扫描仪,点击添加打印机或扫描仪,便很快能找到你的打印机(电脑和打印机要在同一个局域网下)如果找不到可以手动添加http://树莓派ip:631/printers/设置的打印机名即可.

win add
win add

  3.接着你便可以在word等常见应用找到该打印机.

word
word

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 什么是CUPS
  • 准备
  • 开始
    • windows连接打印机
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档