# 4.11 SSH, SCP आणि rsync

Source: https://ravindrabagale.com/mr/aws/ch04-linux-advanced-commands/4-11-remote-access-ssh-and-scp.html
Language: mr (Marathi with English technical terms)

Laptop वरून server login साठी ssh, files copy साठी scp आणि बदललेल्या files sync करण्यासाठी rsync वापरू. Sample IP ऐवजी स्वतःचा server वापरा.

ssh -i ~/keys/mykey.pem ec2-user@13.233.10.25              # log in
ssh -i ~/keys/mykey.pem ubuntu@13.233.10.25 'uptime'        # run one command remotely
scp -i ~/keys/mykey.pem index.html ec2-user@13.233.10.25:/home/ec2-user/        # upload file
scp -i ~/keys/mykey.pem -r ./site ubuntu@13.233.10.25:~/                        # upload folder
scp -i ~/keys/mykey.pem ec2-user@13.233.10.25:/var/log/nginx/error.log .        # download
rsync -avz -e "ssh -i ~/keys/mykey.pem" ./site/ ubuntu@13.233.10.25:~/site/     # smart sync

Error log वाचायला remote user ला permission नसेल तर सुरक्षित user-readable copy तयार करून download करा; private key किंवा logs चे access अनावश्यक उघडू नका.

SSH config मुळे typing कमी

~/.ssh/config मध्ये:

Host web1
    HostName 13.233.10.25
    User ec2-user
    IdentityFile ~/keys/mykey.pem

आता ssh web1 किंवा scp file.txt web1:~/ पुरेसं.

Lab

Host mauli-web entry तयार करा — HostName, User, IdentityFile. ssh mauli-web 'uptime'. मग scp -r ~/labs/mauli mauli-web:~/. एक file बदलून rsync -avz ~/labs/mauli/ mauli-web:~/mauli/ करा; बदललेल्या files चा transfer पाहा.

रवींद्र बागले यांची tip

Remote path आधी colon हवा: user@IP:/path/. तो नसला तर scp local filename समजू शकतो. Key साठी -i किंवा SSH config वापरा; rsync मधला trailing slash देखील अर्थ बदलतो.
