May 26, 2020

MacBookからサーバーにsftpのバッチスクリプトを使えるようにする方法

MacBook の sftp で、 -b オプションの バッチスクリプトを使えるようにする方法

-b オプションの バッチスクリプトは、パスワード認証ではなくて公開鍵認証の設定をしておかないと使えない。

[準備] 

sftp や ssh で、パスワード認証でログインできていること。

[公開鍵認証の設定方法]


watakushi-no-MacBook-Air:xxxx myaccount$ cd ~
watakushi-no-MacBook-Air:~ myaccount$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/myaccount/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): <==(無しでよい)
Enter same passphrase again: <==(無しでよい)
Your identification has been saved in /Users/myaccount/.ssh/id_rsa.
Your public key has been saved in /Users/myaccount/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zMvT1Y/ZP3dwUr0PSkAHOsTk/cNI6cUN2BXBnoL0hT0 myaccount@watakushi-no-MacBook-Air.local
The key's randomart image is:
+---[RSA 3072]----+
|          *++.++.|
|         =.o.+oo |
|        o.o.o =o.|
|       o +.. E .+|
|        Soo.+ =.o|
|       . + +.o+*.|
|        + o...o=+|
|         .  .o .=|
|                =|
+----[SHA256]-----+
watakushi-no-MacBook-Air:~ myaccount$ ls -la .ssh
total 24
drwx------   5 myaccount  staff   160 May 26 22:11 .
drwxr-xr-x+ 20 myaccount  staff   640 May 13 12:01 ..
-rw-------   1 myaccount  staff  2635 May 26 22:11 id_rsa  <=(ssh-keygen が生成した秘密鍵)
-rw-r--r--   1 myaccount  staff   590 May 26 22:11 id_rsa.pub <=(ssh-keygen が生成した公開鍵 : 次に ssh-copy-id でサーバーへ登録する)
-rw-r--r--   1 myaccount  staff   644 Jan 30  2015 known_hosts
watakushi-no-MacBook-Air:~ myaccount$ ssh-copy-id -i ~/.ssh/id_rsa.pub serveraccount@myserver.com
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/myaccount/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
serveraccount@myserver.com's password: <=(正しい password 必要)
......
Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'serveraccount@myserver.com'"
and check to make sure that only the key(s) you wanted were added.

watakushi-no-MacBook-Air:~ myaccount$ sftp serveraccount@myserver.com
Connected to myserver.com.   <=(password なしで接続可能になる == -b オプションで、sftp のバッチスクリプトを渡せるようになった)
sftp> quit
watakushi-no-MacBook-Air:~ myaccount$


No comments:

Post a Comment