LoginSignup
0
2

More than 5 years have passed since last update.

マストドンの新規ユーザーをRails Consoleから作成する

Posted at

マストドンにおいて、Web上の新規会員登録を有効にしたくないけれど、
任意のユーザーを新規作成したい時のメモ。

STEP1 SSHログイン

ssh root@example.com -i pem鍵のパス

STEP2 マストドンを実行しているユーザーでログイン

ユーザーがわからないときは

ps axu | grep puma

とかで調べる。

さくらのスタートアップスクリプトの場合、「mastodon」ユーザーなので

su - mastodon

でmastodonユーザーでログイン

STEP3 マストドンのRailsディレクトリに移動

マストドンのRailsディレクトリに移動。
わからないときは、

ps axu | grep node

とかで調べる。

さくらのスタートアップスクリプトの場合、/home/mastodon/liveなので、

cd /home/mastodon/live

STEP4 Rails Console に入る

bundle exec rails console -e production

STEP5 ユーザーを作る

user = User.create(email:'example@example.com', password:'YOUR_PASSWORD', password_confirmation:'YOUR_PASSWORD')
user.locale = 'ja' # 日本語なら'ja'、英語なら'en'など
user.build_account
user.account.username = 'YOUR_USERNAME' # アルファベットのユーザー名
user.save
# 確認メールが飛びます
user.account.save

build_accountがミソですね。
passwordとpassword_confirmationは同じ値を入れてください。

STEP6 Rails Consoleを抜ける

exit
0
2
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
2