LoginSignup
17
18

More than 5 years have passed since last update.

ssh接続のまとめ

Last updated at Posted at 2014-03-23

毎回忘れるので、まとめます
client側
bash
$ cd ~/.ssh
$ ssh-keygen -f client_rsa -t rsa
$ scp ~/.ssh/client_rsa.pub admin@192.168.1.100:~
$ ssh admin@192.168.1.100

server側
bash
[admin@centos ~]$ cd ~
[admin@centos ~]$ mkdir .ssh
[admin@centos ~]$ chmod 700 .ssh
[admin@centos ~]$ mv ~/client_rsa.pub ~/.ssh
[admin@centos ~]$ cat ~/.ssh/client_rsa.pub >> authorized_keys
[admin@centos ~]$ chmod 600 authorized_keys

client側
bash
$ ssh -i ~/.ssh/client_rsa admin@192.168.1.100

server側
bash
[root@centos ~]# vi /etc/ssh/sshd_config
PasswordAuthentication yes

PasswordAuthentication no
[root@centos ~]# service sshd restart

可能のエラー:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

対策:knownhostでサーバの既存接続を削除したら大丈夫


@termoshtt さんのコメントにより、ssh-copy-idで簡単にできます。

まずはclient側でssh-copy-id設定(mac利用者なら)

$ brew install ssh-copy-id

client側でキー生成とssh-copy-idを利用してserver 側にコピー

$ ssh-keygen -t rsa
$ ssh-copy-id -i ~/.ssh/id_rsa.pub <username>@<host>

それで簡単に終わります

17
18
2

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
17
18