0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

virshにおけるvCenter Server/ESXへのパスワードレス接続

0
Last updated at Posted at 2026-01-03

1. はじめに

  • 適当なLinux環境から、vCenterにvirshで接続してVM一覧を取得してみた。
  • 特に毎回ID/Passwordを指定するのは面倒なので、パスワードレスでの方法を確認した。

2. IDもパスワードも指定しない場合(IDもパスワードも聞かれる)

vCenter接続
# virsh -c vpx://vcsosv-vc.acs.japan.local/IBMCloud/vcs-osv-cluster/host-km000.acs.japan.local?no_verify=1 list --all
Enter username for vcsosv-vc.acs.japan.local [administrator@vsphere.local]:
Enter administrator@vsphere.local's password for vcsosv-vc.acs.japan.local:
 Id     Name                    State
------------------------------------------
 1038   vcs-osv-nsxt-ctrlmgr2   running
 1041   cust-edge02             running
 1046   service-edge01          running
 1165   rhel8-acs-clone         running
 1436   rhel8-acs2              running
 1437   win2025-acs-ad          running
 -      centos-acs-web          shut off
 -      mig-test1               shut off
 -      mig-test2               shut off
 -      rhel8-acs               shut off
 -      rhel8-acs-clone2        shut off
 -      rhel8-acs-clone3        shut off
 -      rhel8-acs-clone4        shut off
 -      syasuda-rhel6-1         shut off
 -      syasuda-rhel9-1         shut off
 -      ubuntu2404-acs          shut off
 -      ubuntu2510-acs          shut off
 -      win2016-acs2            shut off
 -      win2019-acs             shut off
 -      win2022-acs             shut off
ESX接続
# virsh -c esx://host-km000.acs.japan.local?no_verify=1 list --all
Enter username for host-km000.acs.japan.local [root]:
Enter root's password for host-km000.acs.japan.local:
 Id   Name                    State
----------------------------------------
 1    vcs-osv-nsxt-ctrlmgr2   running
 28   rhel8-acs-clone         running
 37   service-edge01          running
 43   cust-edge02             running
 52   rhel8-acs2              running
 53   win2025-acs-ad          running
 -    centos-acs-web          shut off
 -    mig-test1               shut off
 -    mig-test2               shut off
 -    rhel8-acs               shut off
 -    rhel8-acs-clone2        shut off
 -    rhel8-acs-clone3        shut off
 -    rhel8-acs-clone4        shut off
 -    syasuda-rhel6-1         shut off
 -    syasuda-rhel9-1         shut off
 -    ubuntu2404-acs          shut off
 -    ubuntu2510-acs          shut off
 -    win2016-acs2            shut off
 -    win2019-acs             shut off
 -    win2022-acs             shut off

3. IDだけ指定した場合(パスワードが聞かれる)

  • vCenter接続時は、\をURLエンコードして、vsphere.local%5CAdministratorのように記述する必要がある。
vCenter接続
# virsh -c vpx://vsphere.local%5CAdministrator@vcsosv-vc.acs.japan.local/IBMCloud/vcs-osv-cluster/host-km000.acs.japan.local?no_verify=1 list --all
Enter vsphere.local\Administrator's password for vcsosv-vc.acs.japan.local:
 Id     Name                    State
------------------------------------------
 1038   vcs-osv-nsxt-ctrlmgr2   running
 1041   cust-edge02             running
 1046   service-edge01          running
 1165   rhel8-acs-clone         running
 1436   rhel8-acs2              running
 1437   win2025-acs-ad          running
 -      centos-acs-web          shut off
 -      mig-test1               shut off
 -      mig-test2               shut off
 -      rhel8-acs               shut off
 -      rhel8-acs-clone2        shut off
 -      rhel8-acs-clone3        shut off
 -      rhel8-acs-clone4        shut off
 -      syasuda-rhel6-1         shut off
 -      syasuda-rhel9-1         shut off
 -      ubuntu2404-acs          shut off
 -      ubuntu2510-acs          shut off
 -      win2016-acs2            shut off
 -      win2019-acs             shut off
 -      win2022-acs             shut off
ESX接続
# virsh -c esx://root@host-km000.acs.japan.local?no_verify=1 list --all
Enter root's password for host-km000.acs.japan.local:
Id   Name                    State
----------------------------------------
1    vcs-osv-nsxt-ctrlmgr2   running
28   rhel8-acs-clone         running
37   service-edge01          running
43   cust-edge02             running
52   rhel8-acs2              running
53   win2025-acs-ad          running
-    centos-acs-web          shut off
-    mig-test1               shut off
-    mig-test2               shut off
-    rhel8-acs               shut off
-    rhel8-acs-clone2        shut off
-    rhel8-acs-clone3        shut off
-    rhel8-acs-clone4        shut off
-    syasuda-rhel6-1         shut off
-    syasuda-rhel9-1         shut off
-    ubuntu2404-acs          shut off
-    ubuntu2510-acs          shut off
-    win2016-acs2            shut off
-    win2019-acs             shut off
-    win2022-acs             shut off

5. IDもパスワードも指定せずにパスワードレス接続

/etc/libvirt/auth.confに以下のようにファイルを書いておく。

  • authセクション

    • [auth-esx-ホスト名]もしくは[auth-esx-IPアドレス]の様式でセクションを記載する。credentialsには、このセクションが利用するcredentialsセクション名(任意の名前で良い)を記載する。
  • credentialsセクション

    • [credentials-xxxx]のxxxxの箇所に、上記のauthセクションで指定したcredentials値を指定する。
    • 接続ユーザ、パスワードを記載する。
  • 参考リンク: https://libvirt.org/auth.html

/etc/libvirt/auth.conf
[auth-esx-vcsosv-vc.acs.japan.local]
credentials=vcenter

[auth-esx-host-km000.acs.japan.local]
credentials=esxi0

[auth-esx-host-km001.acs.japan.local]
credentials=esxi1

[auth-esx-host-km002.acs.japan.local]
credentials=esxi2

[credentials-vcenter]
username=vsphere.local\Administrator
password=xxxxxxxxxx

[credentials-esxi0]
username=root
password=xxxxxxxxxx

[credentials-esxi1]
username=root
password=xxxxxxxxxx

[credentials-esxi2]
username=root
password=xxxxxxxxxx
vCenter接続
# virsh -c vpx://vcsosv-vc.acs.japan.local/IBMCloud/vcs-osv-cluster/host-km000.acs.japan.local?no_verify=1 list --all
 Id     Name                    State
------------------------------------------
 1038   vcs-osv-nsxt-ctrlmgr2   running
 1041   cust-edge02             running
 1046   service-edge01          running
 1165   rhel8-acs-clone         running
 1436   rhel8-acs2              running
 1437   win2025-acs-ad          running
 -      centos-acs-web          shut off
 -      mig-test1               shut off
 -      mig-test2               shut off
 -      rhel8-acs               shut off
 -      rhel8-acs-clone2        shut off
 -      rhel8-acs-clone3        shut off
 -      rhel8-acs-clone4        shut off
 -      syasuda-rhel6-1         shut off
 -      syasuda-rhel9-1         shut off
 -      ubuntu2404-acs          shut off
 -      ubuntu2510-acs          shut off
 -      win2016-acs2            shut off
 -      win2019-acs             shut off
 -      win2022-acs             shut off
ESX接続
# virsh -c esx://host-km000.acs.japan.local?no_verify=1 list --all
 Id   Name                    State
----------------------------------------
 1    vcs-osv-nsxt-ctrlmgr2   running
 28   rhel8-acs-clone         running
 37   service-edge01          running
 43   cust-edge02             running
 52   rhel8-acs2              running
 53   win2025-acs-ad          running
 -    centos-acs-web          shut off
 -    mig-test1               shut off
 -    mig-test2               shut off
 -    rhel8-acs               shut off
 -    rhel8-acs-clone2        shut off
 -    rhel8-acs-clone3        shut off
 -    rhel8-acs-clone4        shut off
 -    syasuda-rhel6-1         shut off
 -    syasuda-rhel9-1         shut off
 -    ubuntu2404-acs          shut off
 -    ubuntu2510-acs          shut off
 -    win2016-acs2            shut off
 -    win2019-acs             shut off
 -    win2022-acs             shut off
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?