0
0

More than 1 year has passed since last update.

EC2でRayクラスタ作成時に、Jupyter Notebookのパスワード設定

Last updated at Posted at 2022-02-03

Rayクラスター用コンフィグyamlファイルのhead_setup_commands:欄に以下の行を追加する。

Rayクラスター用コンフィグ
# Custom commands that will be run on the head node after common setup.
head_setup_commands: 
    - sudo apt-get install -y python3 python3-pip
    - sudo pip3 install jupyter
    - sudo jupyter notebook --generate-config -y # パスワード設定用のコンフィグファイルを生成
    - echo "c.NotebookApp.password='sha1:***'" | sudo tee /home/ray/.jupyter/jupyter_notebook_config.py # コンフィグファイルにパスワードを設定。「sha1:***」がパスワード。teeコマンドにはsudo要
    - nohup sudo jupyter notebook --ip=* --port=8888 --allow-root >> jupyter.log 2>&1 & # Ray立ち上げ時にjupyter notebookが邪魔しないようにnohupでコマンドを実行し続けるようにする。「nohup <中略> >> jupyter.log 2>&1 &」が該当箇所。「--ip=*」は送信元IPを無制限、「--port=8888」はJupyterをポート8888番で利用、--allow-rootはsudoでの実行を許可、という意味。
    - sudo pip3 install awscli

これでJupyterログイン時にパスワードの入力を求められるようになる。
image.png

sha1:***の部分にはハッシュ値を入れる。下記コマンドでPython3を利用して任意の文字列からハッシュ値を生成できる。

ハッシュパスワード
$ python3 -c 'from notebook.auth import passwd;print(passwd())'
Enter password:
Verify password:
sha1:***********************************
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