LoginSignup
1
3

More than 5 years have passed since last update.

新しくサーバーを立た時用メモ

Last updated at Posted at 2017-06-26

ユーザーを追加する

useradd testuser
passwd testuser

追加したユーザーをsudu権限を持ったグループに追加

- gpasswd -a wheel testuser
+ usermod -aG wheel testuser

wheelの設定を確認

コメントアウトを削除。

visudo

- #%wheel        ALL=(ALL)       ALL
+ %wheel        ALL=(ALL)       ALL

SSHの設定を変更する

SSHのポートを変更して、rootユーザーでのログインを禁止。

/etc/ssh/sshd_config

- Port 22
- PermitRootLogin yes
- PasswordAuthentication yes

+ Port 2222
+ PermitRootLogin no
+ PasswordAuthentication no

再起動して設定を反映。

systemctl restart sshd

firewallから古いポート(22)の設定を削除。

sudo firewall-cmd --permanent --remove-service=ssh

firewalldに設定を追加

元のファイルをコピー。

sudo cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/ssh-2222.xml

新しいポートを指定。

/etc/firewalld/services/ssh-2222.xml
-  <port protocol="tcp" port="22"/>
+  <port protocol="tcp" port="2222"/>

新しいポート設定をfirewallに追加。

sudo firewall-cmd --permanent --add-service=ssh-2222

追加した設定をfirewallに反映。

sudo firewall-cmd --reload
firewall-cmd --list-all

public (default, active)
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh-2222
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

firewalldが自動で起動するようにする。

systemctl enable firewalld

秘密鍵を追加

su testuser
ssh-keygen -t rsa -b 4096 -C "email@example.com"
chmod 700 ~/.ssh
cd ~/.ssh
mv id_rsa.pub authorized_keys
chmod 600 authorized_keys

参考

1
3
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
1
3