CUPS/プリンター共有

提供: ArchWiki
2017年8月8日 (火) 23:33時点におけるKusakata (トーク | 投稿記録)による版 (同期)
ナビゲーションに移動 検索に移動

関連記事

この記事では GNU/Linux システム間、あるいは GNU/Linux システムと Microsoft Windows の間でプリンターを共有する方法を説明しています。

GNU/Linux システム間

サーバーはウェブインターフェイスを使用するか /etc/cups/cupsd.conf を手動で編集することで設定できます。クライアントの設定については、CUPS#ローカルの CUPS サーバーを使わないを見てください。

ウェブインターフェイスを使う

サーバーのウェブインターフェイスを開いて、Administration タブを選択肢、Server の下にある "Share printers connected to this system" オプションを有効にしてください。Change Settings ボタンを押すことで変更が保存され、サーバーは自動的に再起動します。

複雑な設定を行いたい場合、Edit Configuration File を選択することで直接 /etc/cups/cupsd.conf ファイルを編集できます。詳しくは#手動セットアップを見てください。

手動セットアップ

サーバー側のコンピュータ (プリンターに直接接続するコンピュータ) で、location ディレクティブを編集してサーバーへのアクセスを許可してください。例:

/etc/cups/cupsd.conf
<Location />
    Order allow,deny
    Allow localhost
    Allow 192.168.0.*
</Location>
...

また、クライアントが使用する IP アドレスでサーバーが待機するようにしてください:

/etc/cups/cupsd.conf
...
Listen <hostname>:631
...

自動的に設定する方法など、詳しい解説は Using Network Printers を見てください。

編集したら、CUPS を再起動してください。

ソケットアクティベーションを使って CUPS を起動している場合、org.cups.cupsd.socketドロップインファイルを作成してリモート接続でもソケットアクティベーションができるようにしてください:

/etc/systemd/system/org.cups.cupsd.socket.d/override.conf
[Socket]
ListenStream=631

ブラウジングの有効化

ブラウジング (共有プリンターの探知) を有効にするには、サーバーに Avahi をインストールして起動する必要があります。プリンターの探知が必要ない場合、サーバーとクライアントには Avahi が必要ありません。

ノート: cupsd が起動する前に Avahi が立ち上がっていないとブラウジングは機能しません。

ブラウジングを有効にするには、ウェブインターフェイスで Share printers connected to this system を選択するか、手動で Browsing をオンにして BrowseAddress を設定してください:

/etc/cups/cupsd.conf
...
Browsing On
BrowseAddress 192.168.0.*:631
...

org.cups.cupsd サービスを再起動してください。

印刷サーバーの「ブラウジング」はリモートのネットワークホストのブラウジングとは異なります。印刷サーバでは、cupsdavahi-daemon で通信するための DNS-SD プロトコルのサポートを提供します。古い CUPS プロトコルを使用しなければならない場合や、他のネットワークプリンターも印刷サーバーで「ブラウジング」するのでないかぎり、印刷サーバーに cups-browsed サービスは不要です。リモートのネットワークホストには、印刷サーバーのネットワーク通信を「ブラウズ」するための cups-browsed サービスが必須であり、cups-browsed を実行すると自動的に cupsd が起動します。

USB プリンターは接続すると org.cups.cupsd.service サービスが自動的に起動しますが、他の接続タイプでは自動的に起動するとは限りません。cupsd が起動していないと avahi-daemon は印刷サービスを提供することができず、その場合、systemd のサービスユニットファイルを起動時に実行するように修正する必要があります。さらに、依存関係が新しくなったらサービスを再度有効化・インストールしなければなりません。サービスファイルの [Install] セクションを編集して WantedBy=default.target を追加し、org.cups.cupsd.service サービスを起動有効化してください。

GNU/Linux と Windows

Linux サーバー - Windows クライアント

IPP で共有

Windows クライアントを Linux の印刷サーバーに接続するとき推奨される方法は IPP です。HTTP に基づく標準的なプリンタープロトコルであり、ポートフォワーディングやトンネリングなどから様々な恩恵を受けることができます。設定はとても簡単で Samba を使う方法より楽です。IPP は Windows 2000 以降の Windows でネイティブでサポートされています。

ノート: Internet Printing Client を Windows に追加する必要があるかもしれません (Control Panel->Programs->Turn Windows features on or off->Print and Document Services)。

まず、#GNU/Linux システム間に書かれているようにサーバーを設定してください。

Windows コンピュータ側で、コントロールパネル->デバイスとプリンターから「プリンターの追加」を選択します。Windows 10 の場合は「プリンターが一覧にない場合」をクリックしてください。次に、「共有プリンターの名前で選択する」を選んでプリンターの場所を入力してください:

http://hostname:631/printers/printer_name

hostname は GNU/Linux サーバーのホスト名や IP アドレスに、printer_name は接続されているプリンターの名前に置き換えてください。サーバーの完全修飾ドメイン名を使うこともできますが、/etc/cups/cupsd.confServerAlias my_fully_qualified_domain_name を設定する必要があります。

ノート:
  • Windows の 'Add Printer' ダイアログのパスは要注意です。ダイアログボックスが提案している形式は http://computername/printers/printername/.printer ですが、この形式は使えません。代わりに、上に書かれている形式を使ってください。
  • If you are using proxy - check used proxy exclusions twice - it may result in failing to add a printer until reboot even if you will disable proxy at all afterwards (actual for Windows 7).

設定後、Windows コンピュータにプリンターのネイティブなプリンタードライバーをインストールしてください。CUPS のプリンタードライバーを使用するように CUPS サーバーを設定している場合、Windows クライアントでは汎用の postscript プリンターを選択します (例 'HP Color LaserJet 8500 PS' や 'Xerox DocuTech 135 PS2')。テストページを印刷してみて印刷設定をテストしてください。

Samba で共有

クライアントの Windows のバージョンが Windows 2000 以下の場合、あるいは IPP で問題が発生する場合、Samba を使って共有することもできます。ただし Samba を使用する方法もまた複雑です。認証の問題が原因で、設定の難易度が高く、間違いやすいものとなっています。

Linux サーバーの Samba を設定するために、/etc/samba/smb.conf ファイルを編集してプリンターへのアクセスを許可してください。smb.conf ファイルは以下のようになります:

/etc/samba/smb.conf
[global]
workgroup=Heroes
server string=Arch Linux Print Server
security=user

[printers]
    comment=All Printers
    path=/var/spool/samba
    browseable=yes
    # to allow user 'guest account' to print.
    guest ok=no
    writable=no
    printable=yes
    create mode=0700
    write list=@adm root yourusername

プリンターを共有するには上記だけで十分ですが、個別のプリンターのエントリを追加するほうが好ましいでしょう:

/etc/samba/smb.conf
[ML1250]
    comment=Samsung ML-1250 Laser Printer
    printer=ml1250
    path=/var/spool/samba
    printing=cups
    printable=yes
    printer admin=@admin root yourusername
    user client driver=yes
    # to allow user 'guest account' to print.
    guest ok=no
    writable=no
    write list=@adm root yourusername
    valid users=@adm root yourusername

Please note that this assumes configuration was made so that users must have a valid account to access the printer. To have a public printer, set guest ok to yes, and remove the valid users line. To add accounts, set up a regular GNU/Linux account and then set up a Samba password on the server. For instance:

# useradd yourusername
# smbpasswd -a yourusername

設定後、Samba デーモンを再起動してください。

Obviously, there are a lot of tweaks and customizations that can be done with setting up a Samba print server, so it is advised to look at the Samba and CUPS documentation for more help. The smb.conf.example file also has some good samples that might warrant imitating.

Windows サーバー - Linux クライアント

警告: Any special characters in the printer URIs need to be appropriately quoted, or, if your Windows printer name or user passwords have spaces, CUPS will throw a "lpadmin: Bad device-uri" error.

For example: smb://BEN-DESKTOP/HP Color LaserJet CP1510 series PCL6 becomes: smb://BEN-DESKTOP/HP%20Color%20LaserJet%20CP1510%20series%20PCL6.

This result string can be obtained by running the following command:

$ python -c 'from urllib.parse import quote; print("smb://" + quote("BEN-DESKTOP/HP Color LaserJet CP1510 series PCL6"))'

LPD で共有

Windows 7, 8, 10 には LPD サーバーが組み込まれています。それを使うことでクライアントに Samba をインストールしたりサーバーで様々な設定を行うことなく簡単に共有が可能です。Control Panel を開いて Programs -> Activate Windows functionsPrint services から有効にできます。プロパティによってプリンターの shared を有効にする必要があります。共有名には空白なカンマなどの特殊文字を使用してはいけません。

それから CUPS からプリンターを追加できます。LPD プロトコルを選択してください。プリンターアドレスは以下のようになります:

# lpd://windowspc/printersharename

プリンターを追加する前に、使用しているプリンターにあわせて適切なプリンタードライバーをインストールする必要があります。Generic PostScript や RAW ドライバーで動作するかもしれません。

IPP で共有

上記と同じく、プリンターを共有する際は IPP が推奨プロトコルです。ただし、下に書かれている Samba による方法よりも少しばかり難しくなります。Windows に IPP サーバーをセットアップするには労力が必要です。サーバーソフトウェアとしては一般的に Microsoft の Internet Information Services (IIS) が使われます。Windows 10 などクライアント版の Windows には IPP クライアントしか含まれていないため、IPP で共有することはできません。

Samba で共有

A much simpler way is using Window's native printer sharing via Samba. There is almost no configuration needed, and all of it can be done from the CUPS Backend. As above noted, if there are any problems the reason is mostly related to authentication trouble and Windows access restrictions.

On the server side enable sharing for your desired printer and ensure that the user on the client machine has the right to access the printer.

The following section describes how to set up the client, assuming that both daemons (cupsd and smbd) are running.

ウェブインターフェイスを使って設定

Samba の CUPS バックエンドはデフォルトで有効になっていますが、何らかの理由で有効でない場合は以下のコマンドを実行してから CUPS を再起動してください:

# ln -s $(which smbspool) /usr/lib/cups/backend/smb

Next, simply log in on the CUPS web interface and choose to add a new printer. As a device choose "Windows Printer via SAMBA".

For the device location, enter:

smb://username:password@hostname/printer_name

Or without a password:

smb://username@hostname/printer_name

Make sure that the user actually has access to the printer on the Windows computer and select the appropriate drivers. If the computer is located on a domain, make sure the URI includes the domain:

smb://username:password@domain/hostname/printer_name
手動設定

手動で設定する場合、CUPS デーモンを停止して以下のように /etc/cups/printers.conf にプリンターを追加してください:

/etc/cups/printers.conf
<DefaultPrinter MyPrinter>
AuthInfoRequired username,password
Info My printer via SAMBA
Location In my Office
MakeModel Samsung ML-1250 - CUPS+Gutenprint v5.2.7        # <= use 'lpinfo -m' to list available models
DeviceURI smb://username:password@hostname/printer_name   # <= server URI as described in previous section
State Idle
Type 4
Accepting Yes
Shared No
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
AllowUser yourusername                                    # <= do not forget to change this
OpPolicy default
ErrorPolicy stop-printer
</Printer>

設定したら CUPS デーモンを再起動してテスト印刷を行ってみてください。

Windows 印刷サーバーの URI を確認

Windows では正確なデバイス URI (デバイスの場所) が明確ではありません。CUPS でデバイスの場所を指定するときに問題が発生する場合、以下のコマンドを実行して特定の windows ユーザーから利用できる共有を確認できます:

$ smbtree -U windowsusername

Samba が正しく設定されていれば、上記のコマンドでローカルエリアネットワークサブネットで指定した Windows ユーザーから使える全ての共有が表示されます。以下のように出力されます:

WORKGROUP
	\\REGULATOR-PC   		
		\\REGULATOR-PC\Z              	
		\\REGULATOR-PC\Public         	
		\\REGULATOR-PC\print$         	Printer Drivers
		\\REGULATOR-PC\G              	
		\\REGULATOR-PC\EPSON Stylus CX8400 Series	EPSON Stylus CX8400 Series

上記の場合、最後の行がプリンターとわかります。上記の EPSON Stylus プリンターに印刷する場合、CUPS で使用する URI は以下のようになります:

smb://username.password@REGULATOR-PC/EPSON Stylus CX8400 Series

リモート管理

#GNU/Linux システム間に書かれているようにサーバーをセットアップしたら、設定によってリモートで管理することができます。管理を許可するホストを /etc/cups/cupsd.conf<Location /admin> ブロックに追加してください。使用する構文は#手動セットアップで説明されているものと同じです。3つのレベルで権限を与えることができます:

<Location />           #access to the server
<Location /admin>	#access to the admin pages
<Location /admin/conf>	#access to configuration files

リモートホストに与えたいレベルにあわせて、セクションに Allow ステートメントを追加してください。Allow ステートメントは以下の形式で使用することができます:

Allow from all
Allow from host.domain.com
Allow from *.domain.com
Allow from ip-address
Allow from ip-address/netmask
Allow from @LOCAL

Deny ステートメントを使うこともできます。例えば、ローカルネットワークインターフェイスの全てのホストに完全な権限を与えてたい場合、/etc/cups/cupsd.conf を以下のように編集:

# Restrict access to the server...
# By default only localhost connections are possible
<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 Basic
   Require user @SYSTEM
   Order allow,deny
   Allow from @LOCAL
</Location>

以下の設定を追加することでリモートマシンから CUPS ウェブインターフェイスを使用した場合に起こる 426 - Upgrade Required エラーを止めることができます:

DefaultEncryption Never

Kerberos

Kerberos を使ってリモートの CUPS サーバーにアクセスするユーザーを認証することができます。マシンにキータブが存在することが前提で、"HTTP" のチケットが必要です。http://localhost:631 の代わりに https://host.example.co.uk:631 を使ってください。認証するために暗号化 (https) が必要な上に Kerberos/Negotiate を機能させるために完全なホストネームが必要です。さらにサーバーの /etc/cups/cupsd.conf を設定して DefaultAuthTypeNegotiate にする必要があります。

Samba の winbind NSS サポートを使用する場合、AD グループ名を /etc/cups/cups-files.conf に追加することができます。以下の例では sysadmin が AD グループです:

SystemGroup sys root sysadmin

トラブルシューティング

一般的なトラブルシューティングについては CUPS/トラブルシューティングを見てください。

GTK アプリケーションで印刷できない

GTK アプリケーションから印刷しようとすると "getting printer information failed" と表示される場合、/etc/hosts に次の行を追加してください:

# serverip 	some.name.org 	ServersHostname

Samba でプリンターを追加・編集できない

Samba を使ってプリンターを追加・編集しようとすると、インターフェイスによる CPU の使用率が 100% の状態が30秒も続いた後に以下のメッセージが表示される場合:

Unable to get list of printer drivers: Success

Gutenprint (https://bugs.archlinux.org/task/43708) の既知のバグが原因です。Gutenprint をアンインストールして foomatic-db だけをインストールしてください。次のコマンドで "Success" メッセージの代わりにドライバーのリストが返ってくるはずです:

# lpinfo -m

Windows でパーミッションエラー

ユーザーによっては別の構文を使うことで 'NT_STATUS_ACCESS_DENIED' エラーが解決する場合があります (Windows クライアント):

smb://workgroup/username:password@hostname/printer_name

他のオペレーティングシステム

他の印刷システムと CUPS を繋げる方法の詳細は CUPS マニュアルにあります。例: http://localhost:631/help/network.html