2014-10-30 2 views
0

한 서버에서 다른 서버로 데이터를 지속적으로 넣는 쉘 스크립트가 있습니다. 그것은 잘 작동하지만 더 안전하게하고 싶습니다. 따라서 암호가 변경되어 다른 서버가 권한을 거부하면 scipts가 고정됩니다. 가능성이 있습니까? 이렇게되면이 줄이 무시되고 계속 진행됩니다.권한이 거부되면 scp 쉘이 중지됩니다.

inotifywait -m /srv/watchfolderfilme -e create -e moved_to | 
      while read path action file; do 
... 
sshpass -p "****" scp -r /srv/newtorrentfiles/* [email protected]:/srv/torrentfiles && rm -r /srv/newtorrentfiles/* 
done 

답변

4

scp는 문제를 해결할 수있는 최고의 도구가 아닙니다.

George가 말했듯이 ssh로 공개 키를 사용하는 것이 암호 변경을 제거하는 가장 좋은 방법입니다.

또한이 같은 rsync와 함께 트릭을 수행 할 수 있습니다 (이 스크립트는 더 "안전한"확인) 원처럼

rsync -ahz --remove-source-files /srv/newtorrentfiles/ [email protected]:/srv/torrentfiles/ 

또는

rsync -ahz /srv/newtorrentfiles/ [email protected]:/srv/torrentfiles/ && rm -r /srv/newtorrentfiles/* 

모든 작업이 완료되었는지 확인하려면 스크립트가 허락되지 않은 이유로 인해 실패한 경우 전자 메일을 보낼 수 있습니다.

1

아마도 당신이 찾고있는 대답은 아니지만 SSH 키를 사용하지 않는 이유는 무엇입니까?

업데이트 스크립트 :

inotifywait -m /srv/watchfolderfilme -e create -e moved_to | 
      while read path action file; do 
... 
scp -r /srv/newtorrentfiles/* [email protected]:/srv/torrentfiles && rm -r /srv/newtorrentfiles/* 
done 

[email protected]:~> ssh-keygen -t rsa 
Generating public/private rsa key pair. 
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'. 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/a/.ssh/id_rsa. 
Your public key has been saved in /home/a/.ssh/id_rsa.pub. 
The key fingerprint is: 
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 [email protected] 

지금 이미 디렉토리를 존재 (B.에 사용자 B와 같은 디렉토리 ~/스푸핑을 만들 SSH를 사용 할 방법 , 괜찮습니다) :

[email protected]:~> ssh [email protected] mkdir -p .ssh 
[email protected]'s password: 

마지막으로 a의 새 공개 키를 b @ B에 추가합니다

[email protected]:~> ssh [email protected] 

소스 >>http://www.linuxproblem.org/art_9.html

: 당신이 암호없이 A와 같은에서 B로 B에 로그인 할 수 있습니다 지금부터

[email protected]:~> cat .ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys' 
[email protected]'s password: 

: 스푸핑/authorized_keys에와 B의 암호를 마지막으로 시간을 입력