1

I am trying to configure a remote Virtual Machine having Ubuntu 14.04 cloud image to install bind DNS server. Currently I am able to SSH into it using:

ssh.connect( hostname = dns_ip , username = "ec2-user", pkey = k )

I am also able to edit/create files in the /tmp directory using:

stdin, stdout, stderr = ssh.exec_command("cat >> /tmp/named.conf.local")
stdin.write('key ' + domain +'. {\n')
stdin.flush()
stdin.write('algorithm "HMAC-MD5";\n')
stdin.channel.shutdown_write()

However I am unable to do the same in the /etc directory. I have tried:

  1. Changing the file permissions using :

    channel = ssh.invoke_shell() 
    channel.send("sudo chmod 755 /etc/bind/named.conf.local")
    
  2. Generating a script in the remote VM to do the same task

  3. Copying the file from the server to the remote directory

It seems that I cant change the file permissions necessary to write to it and the image I am using does not have a password (I can only access it via key file). Please help me out I have been stuck for 5 hours

fernandezcuesta
  • 2,390
  • 1
  • 15
  • 32
  • If you have python2 you may give fabric a try, or just have a look at its code and check how fabric calls paramiko – fernandezcuesta Aug 13 '15 at 16:54
  • or maybe the destination file is immutable. Double check with lsattr /etc/bind/named.conf.local – fernandezcuesta Aug 13 '15 at 17:02
  • the destination file is very much editable. I can access the virtual machine directly using SSH and edit it as root user. However i cannot do the same with python paramiko library. – Abdul Basit Alvi Aug 13 '15 at 17:37
  • is good example here: http://stackoverflow.com/questions/22587855/running-sudo-command-with-paramiko – dsgdfg Aug 13 '15 at 18:21
  • What do the logs say? logging.getLogger("paramiko").setLevel(logging.DEBUG) – fernandezcuesta Aug 13 '15 at 18:23
  • Giving a system file incorrect permissions is a security hazard and an abuse of the permission system. Write to a temporary file with normal permissions, then use `sudo` to copy it into place with the correct permissions. – tripleee Aug 14 '15 at 04:11

1 Answers1

0

I was able to edit the files after using "root" to SSH to the VM.

ssh.connect( hostname = dns_ip , username = "root", pkey = k )

To SSH as root I followed instructions on this link https://serverfault.com/questions/294892/how-can-i-login-amazon-ec2-with-root-directly-in-putty-or-winscp

Community
  • 1
  • 1