Marci
Marci

Reputation: 457

change sshpass to a more secure solution

I have a python script which contains the following function:

def upload2server(file):
    host_name = 'example.ex.am.com'
    port_num = '432'
    user_name = 'user'
    password = 'passw'
    web_path = '/example/files/'
    full_webpath = user_name + '@' + host_name + ':' + web_path + args.key
    pre_command = 'sshpass -p "' + password + '" scp -P' + ' ' + port_num + ' ' 

    scp_comm = pre_command + file + ' ' + full_webpath 

    os.system(scp_comm)

I'd have 2 questions:

  1. How unsecure is that if I run this script from a remote network using port-forwarding?
  2. Which ways could I make this uploading more secure?

Thanks!

Upvotes: 2

Views: 415

Answers (1)

Kyle
Kyle

Reputation: 1066

Personally, I would generate an SSH keypair for each host and then you can totally forget about using the password in your scp command. Having your password inline isn't a problem per say but it does mean that your password will get recorded in the ~/.bash_history file of that user.

Upvotes: 1

Related Questions