Wednesday, May 22, 2019

SSH force command to copy files with SCP

1. Add the public key to ~/.ssh/authorized_keys with the force command (using python script as an example):


2. On the client side with the private key, run the scp command to copy a directory:

$ scp -o StrictHostKeyChecking=no -r . username@hostname:/path/to/destination

3. In the file on the server side, add the code to handle the scp copying:

origCommandParm = os.environ['SSH_ORIGINAL_COMMAND']
origCommandParmArray = origCommandParm.split()
commandName =  origCommandParmArray[0]
if  commandName == "scp" :
    destination = origCommandParmArra[3]
    cpCommand = "scp -r -d -t " +  destination

No comments:

Get This <