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?

More than 5 years have passed since last update.

SSHの初期設定(公開鍵認証設定とパスワードログインの無効化)

Last updated at Posted at 2019-04-15
  • パーミッションの設定とかどうすればいいかいつも忘れるのでまとめてみました
  • rootで実行する必要があります。
  • python2で書かれています。python3では動きません。OSでデフォルトで入っているのは2ばかりなので問題ないと思います。
  • 保証等は一切ありません。
  • CentOSじゃないと動きません(たぶん)。
sshsettings.py
# -*- coding: utf8 -*-
import os
import time

username = raw_input("input new user name\n>>")
os.system("useradd %s" % unicode(username))
os.system("passwd %s" % unicode(username))
os.system("chmod 701 /home/%s" % unicode(username))
os.system("mkdir /home/%s/.ssh" % unicode(username))
os.system("chmod 700 /home/%s/.ssh" % (unicode(username),))
os.system("chown %s:%s /home/%s/.ssh" % (unicode(username), unicode(username), unicode(username)))
os.system("vi /home/%s/.ssh/authorized_keys" % (unicode(username),))
os.system("chmod 600 /home/%s/.ssh/authorized_keys" % (unicode(username),))
os.system("chown %s:%s /home/%s/.ssh/authorized_keys" % (unicode(username), unicode(username), unicode(username)))
print "please change setting password authentication -> no"
time.sleep(2)
os.system("vi /etc/ssh/sshd_config")
os.system('usermod -aG wheel ' + username)
print "ssh setting finished."
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?