title: Getting "must be run from a terminal" when switching to root user using Paramiko module in Python
body: <p>I am trying to automate a task through a Python script. The idea is to login as a regular user and then send a <code>su</code> command and switch to the root account. </p>
  
  <p>The reason I can't directly login as root is that <code>SSHD</code> doesn't allow root logins.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>ip='192.168.105.8'
  port=22
  username='xyz'
  password='abc'
  ssh=paramiko.SSHClient()
  ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  ssh.connect(ip,port,username,password)
  print ("SSH connection established")
  
  stdin,stdout,stderr=ssh.exec_command('sudo fast.sh')
      outlines=stdout.readlines()
      outlines+=stderr.readlines()
      resp=''.join(outlines)
      print(resp)
  </code></pre>
  
  <p>Now, I want to send the <code>su</code> command and echo the root password. I am aware this is not good practice but I need a quick and easy way to test this so I am OK with that.</p>
  
  <p>However, when I do this
  <code>stdin,stdout,stderr=ssh.exec_command('su')</code> and provide the password, I get an error </p>
  
  <blockquote>
    <p>su: must be run from a terminal</p>
  </blockquote>
  
  <p>Can some one help me to solve this. </p>
  
  <p>I am running Python script on my Windows laptop to ssh into a Linux device and then switch to the <code>root</code> user using the <code>su</code> command and echo the password so that I can run other commands as root.</p>
  
  <p>Thanks.</p>