Skip to content

Instantly share code, notes, and snippets.

@greenido
Created August 2, 2023 22:00
Show Gist options
  • Save greenido/6758285a2d32fdc2cf9211cd5ca43fe2 to your computer and use it in GitHub Desktop.
Save greenido/6758285a2d32fdc2cf9211cd5ca43fe2 to your computer and use it in GitHub Desktop.
A shell script that accesses a server over SSH and copies a specific directory
#!/bin/bash 
# Set the variables. 
server_ip="192.168.1.100" 
username="user" 
password="passwd" 
source_directory="/home/user/my_directory" 
destination_directory="/opt/my_directory" 
# Connect to the server. 
ssh -i ~/.ssh/id_rsa $username@$server_ip 
# Copy the directory. 
cp -r $source_directory $destination_directory 
# Disconnect from the server.
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment