Cent OSの初期設定

sudoを使えるように

まずrootになる

[braitom@localhost ~]$ su - root
Password: 
[root@localhost ~]# 

visudoで以下を編集。

[root@localhost ~]# visudo

## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
braitom ALL=(ALL)       ALL  ←ここを追加

rootを抜けてsudoできることを確認。

[root@localhost ~]# exit
logout
[braitom@localhost ~]$ sudo ls

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for braitom: 
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
[braitom@localhost ~]$ 

※参考さくらVPS+CentOS:自分をsudoユーザに追加してみた

SSH設定

opensshインストール

[braitom@localhost ~]$ sudo yum install openssh

sshd_configを編集。

[braitom@localhost ~]$ sudo vi /etc/ssh/sshd_config 

とりあえず必要最低限

#   $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem   sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#   X11Forwarding no
#   AllowTcpForwarding no
#   ForceCommand cvs server

AllowsUsers braitom

sshdをリスタート

[braitom@localhost ~]$ sudo /etc/rc.d/init.d/sshd restart

※参考CentOS 6.3でSSH

外からPingとか通るようにする。

fusionだとこれ。 CentOS on VMware Fusionネットワークアダプタの構成メモ

VirtualBoxならこの辺が参考に。 ネットワークカードに複数のIPアドレスを付与する Virtualbox上のUbuntuにSSHで接続するための設定手順

これで外からもSSHでつなげるはず。

Macへpyenvをインストールする。

githubのInstallation通り。

インストール

  1. ホームディレクトリに移動してgit cloneする

     $ cd ~
     $ git clone git://github.com/yyuu/pyenv.git .pyenv
    
  2. Pathやinit設定

     $ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
     $ echo 'eval "$(pyenv init -)"' >> ~/.bashrc 
    
  3. source実行

     $ source ~/.bashrc
    

使い方

  1. インストールできるバージョンの一覧取得

     $ pyenv install -l
    
  2. インストール

     $ pyenv install 2.7.5
    
  3. グローバルにセット

     $ pyenv global 2.7.5
    

pyenv rehash 必要かも。

virtualenv

こいつもついでに入れておく

$ cd ~/.pyenv/plugins
$ git clone git://github.com/yyuu/pyenv-virtualenv.git

brewupdateで失敗するときの対処法

brew update すると以下のような感じでこけることがある。というか非常によくある。

braitom-no-Mac-mini:local braitom$ brew update
error: unable to unlink old '.gitignore' (Permission denied)
error: unable to unlink old 'README.md' (Permission denied)
error: unable to create file SUPPORTERS.md (Permission denied)
Checking out files: 100% (925/925), done.
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master

こんなときは以下のリンクのどれかを試せば直る。

rspecの自動実行

guardを使うとできるようです。

  1. guardのインストール guardとguard-rspecをいれる。

      gem install guard
      gem install guard-rspec
    
  2. guard initファイルの作成 対象のプロジェクトのディレクトリで実行。

      guard init
    

    実行すると、「Guardfile」という名前のファイルができる。

  3. 自動実行 Guardfileのあるディレクトリで以下を実行

      guard start
    

    これでファイルに変更がある度にrspecがはしる。

WebStorm 6.0からの機能:File Watchers

コンパイルする系の言語の扱いが非常に便利になったみたい。

CoffeeScriptの場合

「Settings → File Watchers」からCoffeeScript作成。(CoffeeScriptプラグインが入ってればデフォルトで多分入っている)

以下のように設定すればOK。 File Watchers設定画面

参考

WebStorm6のFile WatchersとIDE Improvementsがいいね!

MacにRuby環境構築

インストール

brewが入っていることが前提

  1. brew updateする brewが最新でないといろいろダメなことがあるので。

      brew update
    

    opensslとreadlineも入れておいたほうがいいみたい。

      brew install openssl
    
      brew install readline
    
  2. rbenbいれる

     brew install rbenv
    
  3. ruby-buildいれる

     brew install ruby-build
    
  4. .bashrcに環境変数設定

     export PATH="$HOME/.rbenv/bin:$PATH"
     eval "$(rbenv init -)"
    

    bashrc変更したら、source ~/.bashrcを忘れずに。

  5. rubyのインストール インストール可能なrubyのバージョン一覧が以下のコマンドで見れる。

      rbenv install -l
    
  6. Rubyのインストール opensslとreadlinebrewで入れたものを使いたいのでそのパスを指定する。

      CONFIGURE_OPTS="--with-readline-dir=/usr/local --with-openssl-dir=/usr/local" rbenv install 1.9.3-p392
    

Rubyのバージョン切り替え

現在のversionの確認

braitom-no-Mac-mini:~ braitom$ rbenv version
system (set by /Users/braitom/.rbenv/version)
braitom-no-Mac-mini:~ braitom$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
  • システム全体でしようするRubyのバージョンを指定

      rbenv global 1.9.3-p392
    

    その後、rehash実行

      rbenv rehash
    

    もう一度、バージョンを確認し、変更されていることを確認

      braitom-no-Mac-mini:~ braitom$ rbenv version
      1.9.3-p392 (set by /Users/braitom/.rbenv/version)
      braitom-no-Mac-mini:~ braitom$ ruby -v
      ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.2.1]
    

参考

Mac OS X 10.7.5 (LION) へrbenv + ruby-buildを利用してRuby実行環境を構築する | 完熟トマト

Homebrew + rbenv + ruby-buildでruby 2.0.0-p0をインストール #Ruby - Qiita

Sublime Text 2の設定など

行った設定、入れたプラグイン等を随時メモしていきます。 Package Controlはいれている前提。

Settings -User

{
    "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
    "font_size": 14.0,
    "highlight_modified_tabs": true,
    "scroll_past_end": true,
    "highlight_line": true
}

AutoFileName

jsやらCSSやらimgのファイルパス名を補完してくれる。

sublime-closure-linter

事前にClosure Linterを入れておく必要があります。インストール方法はここ。How to Use Closure Linter - Closure Tools — Google Developers
Closure Linterの実行は、 ctrl+shift+j
Fix JavaScript Styleの実行は、 ctrl+alt+shift+j

/bin/sh: fixjsstyle: command not found

とか出たら正しいパスを設定してあげればOK。
Preferences > Package Settings > Closure Linter > Settings – User
Macならデフォルトだとこんな感じ。

{
    "gjslint_path": "/usr/local/bin/gjslint",
    "fixjsstyle_path": "/usr/local/bin/fixjsstyle"
}

JsFormat

その名の通り。

CSScomb

CSSプロパティを綺麗にソートしてくれる。
デフォルト設定では、ctr + shift + c でフォーマット。

BracketHighlighter

括弧、カンマ、HTMLタグのペアをハイライトしてくれる。
ハイライト色の設定は以下のリンクが参考になる。
Sublime Text 2: Bracket Highlighter

Markdown Preview

その名の通り。プレビューを見るのはあくまでもでブラウザで表示。公式のReedMeにあるようにショートカットを割りあてておくのがおすすめ。
LiveReloadも一緒に入れておけばファイルをセーブするとそのままブラウザ上のプレビューに反映されるので便利。

Markdown Editing

Markdownの編集をちょっと便利にしてくれる。

SideBar Enhancements

その名の通り。サイドバーを拡張する。右クリックでいろいろできるようになる。

SublimeCodeIntel

ctrl + space を押さなくても入力中に補完候補を出してくれる。

Local History

ファイルを保存するたびに履歴を保存してくれる。差分表示も可能。便利。

SublimeLinter

lint系詰め合わせ。リアルタイムチェックも可能。細かいことはGithubのReedMe見るべし。
JavaScriptについては以下が参考になる。
macのテキストエディタ Sublime Text2でJavaScriptのシンタックスエラーチェックをリアルタイムで行う方法
Mac OS X + SublimeLinterでJavascriptの日本語エラーを回避する方法

Tag

HTMLをフォーマットしてくれる。他にも指定した要素を消したりなどHTMLに対していろいろできる。

Terminal

開いているファイルをカレントディレクトリにしてTerminal開いてくれる。
command + shift + t で開いているファイルのディレクトリでTerminal開く。
command + shift + option + t でプロジェクトフォルダでTerminal開く

HTML5

HTML5スニペット

jQuery

jQueryの関数を補完

Clipboard History

コピーしたものを保存してくれる。
Macだとデフォルトで「Command + option + control + v」でクリップボード履歴表示。

CoffeeScript

CoffeeScriptシンタックスハイライトとか

CoffeeCompile

.coffeeファイルをコンパイルして表示できる

ConvertToUTF8

Shift_JISUTF-8に変換してくれる。

SublimeOnSaveBuild

保存時に自動的にビルドを走らせることができる。

参考