Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

currently, i have statements like : system("ssh -o StrictHostKeyChecking=no root\@${address} \"cat /var/log/messages""); This did not require a password, since the two systems were setup with proper key exchange

now this is no longer available: hence:

i want to be able to :

  1. Login as "admin"
  2. Supply a password
  3. do a sudo -i
  4. supply a password
  5. run the same command "cat /var/log/messages"

Thanks, -Kamal.

share|improve this question
Why would you run 'sudo -i' and then 'cat /var/log/messages'? Wouldn't it make a lot more sense to just do 'sudo cat /var/log/messages'? Or, better yet, change /etc/sudoers so admin doesn't need to supply a sudo password. Or, still even better yet, change the permissions of /var/log/messages and/or the group membership of the admin user so they don't need a password to view /var/log/messages. – Christopher Cashell Jul 9 '10 at 16:26

When using Perl, always look for a module in CPAN for the task. Almost certainly someone has already solved your problem. In this case: Net::SSH::Perl.

share|improve this answer

Rather than use sudo, you can probably just add the "admin" user to the group of the /var/log/messages file. On a typical Debian/Ubuntu system, this would mean adding the "admin" user to the "adm" group, since that is the group of the /var/log/messages file.

To add the admin user to the "adm" group:

 sudo adduser admin adm

Then, just use ssh without sudo to cat the file.

Another option is to edit your /etc/sudoers file (using visudo) to allow the admin user to run that command without a sudo password.

share|improve this answer

use Net::OpenSSH.

On the samples directory from the module distribution you will find some scripts automating sudo interaction.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.