Exploring and Thinking

Passwordless scp file to Synology NAS

Synology 要先開啟ssh與home directory功能。

前往homes目錄

cd /var/services/homes

將該使用者的目錄權限設為755。(原本是777,底下以bkuser帳號為例)

chmod 755 bkuser

在帳號的home上新增.ssh目錄

mkdir ~/.ssh/

目錄權限設為700

chmod 700 ~/.ssh/

編輯 /etc/ssh/sshd_config 檔案,將參數改為下方數值

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys

在來源主機產出key (詢問通通按enter)

ssh-keygen -t rsa

查詢是否產生成功

$ cd ~/.ssh
$ ll
total 12
-rw------- 1 user user 1679 Jun  2 15:02 id_rsa
-rw-r--r-- 1 user user  391 Jun  2 15:02 id_rsa.pub

接著將id_rsa.pub檔案scp到NAS

scp ~/.ssh/id_rsa.pub bkuser@192.168.20.102:~/.ssh

在NAS裡,把id_rsa.pub內容加進同一層目錄的authorized_keys檔案中

cat id_rsa.pub >> authorized_keys

authorized_keys檔權限要設為644
chmod 644 authorized_keys

來源主機使用scp,會在.ssh目錄多一個known_hosts的檔案,之後就不會再詢問密碼了!
Share:

熱門文章

標籤