Skip to content

Instantly share code, notes, and snippets.

@satomixx
Created April 19, 2013 02:27
Show Gist options
  • Save satomixx/5417676 to your computer and use it in GitHub Desktop.
Save satomixx/5417676 to your computer and use it in GitHub Desktop.
さくらVPS 1GB に CentOS6.4 を入れて、 環境構築1 - ssh など ref: http://qiita.com/items/533f591cf5d79b81a3aa
# cat /etc/redhat-release
CentOS release 6.4 (Final)
# vim /proc/cpuinfo
model name : Intel(R) Xeon(R) CPU E5645
cpu MHz : 2400.032
cache size : 4096 KB
・・・
$ ssh root@xxx.xxx.xxx.xxx -p 22
$ mkdir ~/.ssh/[vpsの名前]/
$ cd ~/.ssh/[vpsの名前]/
$ ssh-keygen -t rsa
名前の指定部分⇒ id_rsa.[vpsの名前等]
パスワード⇒ ご自由に
ls
$ scp id_rsa.[vpsの名前].pub root@xxx.xxx.xxx.xxx:/home/USER_NAME/.ssh/authorized_keys
$ ssh root@xxx.xxx.xxx.xxx -p 22
# su - USER_NAME
$ sudo chown USER_NAME:USER_NAME .ssh/authorized_keys
$ chmod 600 /home/USER_NAME/.ssh/authorized_keys
$ sudo/etc/init.d/sshd restart
$ exit
$ vim ~/.ssh/config
--------
Host [任意のお名前(私はsakura01とかにしました)]
HostName xxx.xxx.xxx.xxx
Port [サーバーで決めたPort番号]
User USER_NAME
identityfile ~/.ssh/VPS_NAME/id_rsa.[vpsの名前] # ←ここは.pubじゃありません。.pubはサーバーに送った公開鍵で、ローカルにある鍵のことは秘密鍵といい、ここでは秘密鍵の指定をします。
--------
$ssh [先ほど指定した任意のお名前]
// ssh sakura01 ←私の場合
ちなみにこれをしないと以下の様なコマンドをほぼ毎回打つことになります。
$ ssh USER_NAME@HostName -p [ポート番号] -i [鍵のパス]
めんどいですね(((( ´,,_ゝ`)))) ププッ プルプルッ
$ sudo vim /etc/hosts.allow
--------
ALL: 127.0.0.1
sshd: .jp
--------
$ sudo vim /etc/hosts.deny
--------
sshd: ALL
--------
# useradd USER_NAME -G wheel
# passwd USER_NAME
# この USER_NAME のところに自由にユーザー名を指定
確認します。
$ id satomi
uid=500(satomi) gid=500(satomi) 所属グループ=500(satomi),10(wheel)
$ sudo yum update
sudo vim /etc/pam.d/su
--------
# auth required pam_wheel.so use_uid
auth required pam_wheel.so use_uid
--------
コメントアウトを外します。
root権限を使えるグループをwheelに指定します。
$ sudo vim /etc/login.defs
--------
SU_WHEEL_ONLY yes
--------
ファイルの最終行に上の一行を追加ます。
ちなみにvimで最終行に行くには *Shift+g* で行けます。
指定行には */ + [行きたい行数]* もしくは *[行きたい行数] + Shift+g* です。
$ sudo visudo
--------
# %wheel ALL=(ALL) ALL
%wheel ALL=(ALL) ALL
--------
$ sudo vim /etc/ssh/sshd_config
--------
PermitRootLogin no
PasswordAuthentication no
--------
$ sudo vim /etc/ssh/sshd_config
--------
Port xxxxx
--------
この行をファイルの一番下に追加。 xxxxxは 0 ~ 65535 の間で選択可能。(ホントは49152 ~ 65535という指定があるのですが、今は気にしなくても大丈夫。詳しく知りたい場合はコチラ⇒http://ja.wikipedia.org/wiki/%E3%83%9D%E3%83%BC%E3%83%88%E7%95%AA%E5%8F%B7)
su - USER_NAME
mkdir ~/.ssh/
chmod 700 ~/.ssh/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment