Skip to content

Instantly share code, notes, and snippets.

@sainu
Last active April 15, 2017 10:15
Show Gist options
  • Save sainu/fc5d850ad4fa1ea4b345a61a9126ffa1 to your computer and use it in GitHub Desktop.
Save sainu/fc5d850ad4fa1ea4b345a61a9126ffa1 to your computer and use it in GitHub Desktop.
Dropbox/.ssh/の鍵ファイルを全て~/.sshにシンボリックリンクを貼るスクリプトを書いた ref: http://qiita.com/saino-katsutoshi/items/216f594468d0b79bdb54
$ pwd
/path/to/Dropbox/.ssh
$ tree .
.
├── config
├── id_hoge_rsa
├── id_hoge_rsa.pub
└── hoge.pem
$ pwd
/path/to/Dropbox/.ssh
$ touch setup.sh
$ chmod 755 setup.sh
$ vim setup.sh
$ pwd
/path/to/Dropbox/.ssh
$ ./setup.sh
$ cd ~/.ssh
$ ls -la
lrw-r--r-- 1 me staff 42 4 15 18:24 config@ -> /path/to/Dropbox/.ssh/config
$ vim config
Host hogehoge
...(中略)...
#!/bin/sh
files=`find . -maxdepth 1 -type f | sed "s!^.*/!!" | grep -vE "setup.sh|.DS_Store"`
for file in $files; do
file_path=`pwd`/$file
target_dir_path=$HOME/.ssh/
ln -s $file_path $target_dir_path
target_file_path=$target_dir_path/$file
if [[ $file =~ '.pem' ]]; then
chmod -h 400 $target_file_path
elif [[ $file =~ '.pub' ]]; then
chmod -h 644 $target_file_path
elif [[ $file =~ 'config' ]]; then
chmod -h 644 $target_file_path
else
chmod -h 600 $target_file_path
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment