[root@ip:/tmp] ssh root@ip "sudo -u bob date" root@ip's password: sudo: sorry, you must have a tty to run sudo [root@ip:/tmp] but ssh -t root@ip "sudo -u bob date" solves the problem #### use Carp qw(carp confess croak); use Net::SSH2; my $host = "ip"; my $user = "root"; my $pass = "mypassword"; # Connect to host my $ssh = Net::SSH2->new(); if (! $ssh->connect($host)) { print "Failed connection to $host\n"; exit(1); } if ($pass ne "") { if (! $ssh->auth_password($user,$pass)) { print "FAILED SCP password authentication for $username to $host\n"; exit(1); } } else { print "FAILED SCP not the correct credentials provided in config file\n"; exit(1); } my $chan = $ssh->channel(); $chan->exec($ARGV[$0]); $stdout = undef; $chan->read( $stdout, 10000 ); $chan->close(); print $stdout; $ssh->disconnect(); exit(0); #### perl myssh.pl "sudo -u bob date" won't work perl myssh.pl "date" works and gives the date command output.