scp with password less authentication is working fine but if delete a file on the source it will not get replicated ie the destination directory is not completely replaced with source. I can see the new files or modifications are properly get replicated.
scp -r /user/local/img [email protected]:/user/local/img
scp is only a copy tool, so if you have to use scp, your only real choice is to empty the destination directory tree first.
Alternatively, you should probably look into using rsync, this will run over ssh using the passwordless setup you have now, and has many advantages (it can replicate deletes, only transfers changed data so copies are quicker, and can compress data during transfer). If you change your command to this one, you should get the results that you want (although test it first to make 100% sure it does what you're looking for!):
rsync -avz --del /user/local/img [email protected]:/user/local/img
scp
works much like standardcp
- it copies what you tell it to copy. Your command above says that it should copy the local folder/usr/local/img
to/usr/local/img
on the remote server; if the remote folder already exists, then it'll copy to/usr/local/img/img
.scp is much the same as cp it doesn't delete destination files if the source has been deleted . If you want to keep source and destination directories in sync then rsync is the way forward.
you can also use rsync over ssh