MENU
Language

XServerVPS : DIFYの管理者のパスワードを忘れた場合の対処法 – サーバーにログインできる場合のパスワードのリセット手順

Difyの管理者パスワードを忘れた場合でも、サーバーにログインできる環境があれば、以下の手順でパスワードをリセットできます。


目次

手順:Difyの管理者パスワードをリセットする

サーバーにログイン

ssh username@your_server_ip

Dockerコンテナで動作しているデータベースの確認

サーバーがDockerを使用している場合、コンテナ内でデータベースが動作している可能性があります。

docker ps | grep -i 'postgres\|mysql\|mariadb'

結果の例)

ab1234512345   postgres:15-alpine "docker-entrypoint.s…"   2 weeks ago   Up 2 weeks (healthy)   5432/tcp docker-db-1

docker-db-1という名前のコンテナがpostgres:15-alpineのイメージを使用して稼働していることがわかります。この情報に基づいて、PostgreSQLデータベースにアクセスする方法を以下に説明します。

1. コンテナ内に入る

まず、Dockerコンテナ内にアクセスしてPostgreSQLに直接接続できるか確認します。

docker exec -it docker-db-1 sh

これにより、docker-db-1コンテナ内のシェルにアクセスできます。


2. PostgreSQLクライアントを使用して接続

コンテナ内に入ったら、PostgreSQLに接続します。

psql -U postgres
  • -U postgres は、デフォルトの管理者ユーザーです。
  • 初期設定では、パスワードなしでログインできる場合もあります。

3. 外部からアクセスする

ホストマシンから直接PostgreSQLに接続する場合、コンテナのポート5432が公開されている必要があります。公開されていることを確認し、以下のように接続します。

ホストから接続コマンド

psql -h localhost -p 5432 -U postgres
  • -h localhost: ホスト名(コンテナがローカルで動作している場合はlocalhost)。
  • -p 5432: PostgreSQLのポート番号。
  • -U postgres: 管理者ユーザー。

もしホストがlocalhost以外の場合は、そのIPアドレスまたはホスト名を指定します。


4. 環境変数での設定確認

コンテナ内や.envファイルにデータベース接続情報が記載されていることがあります。以下のように確認してください。

コンテナ内で環境変数を確認

env | grep -i 'postgres'

環境変数にPOSTGRES_PASSWORDPOSTGRES_DBなどの情報が含まれている場合、それが接続情報です。


5. データベースのリストを確認

PostgreSQLにログインしたら、以下のコマンドでデータベースの一覧を確認できます。

\l

出力例)

                                                List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    | ICU Locale | Locale Provider |   Access privileges   
-----------+----------+----------+------------+------------+------------+-----------------+-----------------------
 dify      | postgres | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | 
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | 
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/postgres          +
           |          |          |            |            |            |                 | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/postgres          +
           |          |          |            |            |            |                 | postgres=CTc/postgres

6. データベースに接続

データベース名が dify であることが確認できたら、以下のコマンドで切り替えます。

\c dify
  • 成功すると、以下のようなメッセージが表示されます:
You are now connected to database "dify" as user "postgres".

7. テーブル一覧を表示

データベースに接続した後、SQLクエリを実行できます。

例:

\dt

結果の例)

                      List of relations
 Schema |               Name                | Type  |  Owner   
--------+-----------------------------------+-------+----------
 public | account_integrates                | table | postgres
 public | accounts                          | table | postgres
 public | alembic_version                   | table | postgres
 public | api_based_extensions              | table | postgres
 public | api_requests                      | table | postgres
 public | api_tokens                        | table | postgres
 public | app_annotation_hit_histories      | table | postgres
 public | app_annotation_settings           | table | postgres
 public | app_dataset_joins                 | table | postgres
 public | app_model_configs                 | table | postgres
 public | apps                              | table | postgres
 public | celery_taskmeta                   | table | postgres
 public | celery_tasksetmeta                | table | postgres
 public | conversations                     | table | postgres
 public | data_source_api_key_auth_bindings | table | postgres
 public | data_source_oauth_bindings        | table | postgres
 public | dataset_collection_bindings       | table | postgres
 public | dataset_keyword_tables            | table | postgres
 public | dataset_permissions               | table | postgres
 public | dataset_process_rules             | table | postgres
 public | dataset_queries                   | table | postgres
 public | dataset_retriever_resources       | table | postgres
 public | datasets                          | table | postgres
 public | dify_setups                       | table | postgres
 public | document_segments                 | table | postgres
 public | documents                         | table | postgres
 public | embeddings                        | table | postgres
 public | end_users                         | table | postgres
 public | external_knowledge_apis           | table | postgres
 public | external_knowledge_bindings       | table | postgres
 public | installed_apps                    | table | postgres
 public | invitation_codes                  | table | postgres
 public | load_balancing_model_configs      | table | postgres
 public | message_agent_thoughts            | table | postgres
 public | message_annotations               | table | postgres
 public | message_chains                    | table | postgres
 public | message_feedbacks                 | table | postgres
 public | message_files                     | table | postgres
 public | messages                          | table | postgres
 public | operation_logs                    | table | postgres
 public | pinned_conversations              | table | postgres
 public | provider_model_settings           | table | postgres
 public | provider_models                   | table | postgres
 public | provider_orders                   | table | postgres
 public | providers                         | table | postgres
 public | recommended_apps                  | table | postgres
 public | saved_messages                    | table | postgres
 public | sites                             | table | postgres
 public | tag_bindings                      | table | postgres
 public | tags                              | table | postgres
 public | tenant_account_joins              | table | postgres
 public | tenant_default_models             | table | postgres
 public | tenant_preferred_model_providers  | table | postgres
 public | tenants                           | table | postgres
 public | tidb_auth_bindings                | table | postgres
 public | tool_api_providers                | table | postgres
 public | tool_builtin_providers            | table | postgres
 public | tool_conversation_variables       | table | postgres
 public | tool_files                        | table | postgres
 public | tool_label_bindings               | table | postgres
 public | tool_model_invokes                | table | postgres
 public | tool_providers                    | table | postgres
 public | tool_published_apps               | table | postgres
 public | tool_workflow_providers           | table | postgres
 public | trace_app_config                  | table | postgres
 public | upload_files                      | table | postgres
 public | whitelists                        | table | postgres
 public | workflow_app_logs                 | table | postgres
 public | workflow_conversation_variables   | table | postgres
 public | workflow_node_executions          | table | postgres
 public | workflow_runs                     | table | postgres
 public | workflows                         | table | postgres
(72 rows)

8.accounts テーブルの項目を確認

\d accounts

 結果の例)

                                       Table "public.accounts"
       Column       |            Type             | Collation | Nullable |           Default           
--------------------+-----------------------------+-----------+----------+-----------------------------
 id                 | uuid                        |           | not null | uuid_generate_v4()
 name               | character varying(255)      |           | not null | 
 email              | character varying(255)      |           | not null | 
 password           | character varying(255)      |           |          | 
 password_salt      | character varying(255)      |           |          | 
 avatar             | character varying(255)      |           |          | 
 interface_language | character varying(255)      |           |          | 
 interface_theme    | character varying(255)      |           |          | 
 timezone           | character varying(255)      |           |          | 
 last_login_at      | timestamp without time zone |           |          | 
 last_login_ip      | character varying(255)      |           |          | 
 status             | character varying(16)       |           | not null | 'active'::character varying
 initialized_at     | timestamp without time zone |           |          | 
 created_at         | timestamp without time zone |           | not null | CURRENT_TIMESTAMP(0)
 updated_at         | timestamp without time zone |           | not null | CURRENT_TIMESTAMP(0)
 last_active_at     | timestamp without time zone |           | not null | CURRENT_TIMESTAMP(0)
Indexes:
    "account_pkey" PRIMARY KEY, btree (id)
    "account_email_idx" btree (email)

9. テーブル内のデータを確認

テーブルにどのようなデータが格納されているかを確認するには、以下のクエリを使用します。

SELECT * FROM <table_name> LIMIT 10;

例: accountsテーブルの場合

SELECT * FROM accounts LIMIT 10;

データのサンプルを10行まで表示します。
SQL実行結果から、管理者のメールアドレスを確認できます。

10. 管理者アカウントのパスワードをリセットする方法

Dockerの実行中に以下のコマンドでパスワードをリセットすることができます:

docker exec -it docker-api-1 flask reset-password

メールアドレスと新しいパスワードを入力するプロンプトが表示されます。例えば:Copy

None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
2025-01-06 13:25:52,769.769 INFO [MainThread] [utils.py:160] - NumExpr defaulting to 4 threads.
Email: test@test.com
New password: newpassword123
Password confirm: newpassword123
Password reset successfully.

11. 新しいパスワードでログイン

ブラウザでDifyにアクセスし、管理者アカウントでログインします。


注意点

  • 新しいパスワードを記録し、安全に保管してください。
  • パスワード変更後、他のシステムやサービスと連携している場合は、必要に応じて設定を更新します。

不明な点がある場合は、サーバー管理者やシステムの担当者に相談することをお勧めします。

参考

Difyマニュアル – 4. 管理者アカウントのパスワードをリセットする方法
https://docs.dify.ai/ja-jp/getting-started/install-self-hosted/faq

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

AIアーティスト | エンジニア | ライター | 最新のAI技術やトレンド、注目のモデル解説、そして実践に役立つ豊富なリソースまで、幅広い内容を記事にしています。フォローしてねヾ(^^)ノ

コメント

コメントする

目次