• Share
  • ?
  • Profiles ▼
  • Communities ▼
  • Apps ▼

Blogs

  • My Blogs
  • Public Blogs
  • My Updates
  • Administration
  • Log in to participate

▼ Tags

 

▼ Similar Entries

Next Linux webcast: ...

Blog: Ingolf's z/VS...
Ingolf24 120000DRN3
Updated
0 people like thisLikes 0
No CommentsComments 0

Announcing IBM High-...

Blog: Dino Quintero...
DinoQuintero 2700050KT5
Updated
0 people like thisLikes 0
No CommentsComments 0

International Linux ...

Blog: Ingolf's z/VS...
Ingolf24 120000DRN3
Updated
0 people like thisLikes 0
No CommentsComments 0

New webcast tomorrow...

Blog: Ingolf's z/VS...
Ingolf24 120000DRN3
Updated
0 people like thisLikes 0
No CommentsComments 0

New webcast: Pervasi...

Blog: Ingolf's z/VS...
Ingolf24 120000DRN3
Updated
0 people like thisLikes 0
No CommentsComments 0

▼ Archive

  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012

▼ Blog Authors

Brian Smith's AIX / UNIX / Linux / Open Source blog

View All Entries
Clicking the button causes a full page refresh. The user could go to the "Entry list" region to view the new content.) Entry list

Copy files to remote servers with root authority using cat, sudo, and SSH

brian_s 270002K5X3 | | Tags:  ssh aix linux sudo ‎ | 1 Comment ‎ | 20,420 Views

Often times System Administrators need to copy a file to remote servers with root authority.  One example might be to push out an updated resolv.conf file to all servers.   However, often times remote root logins are disabled so it can be difficult to copy files with root authority if root logins are disabled.

 

Here is a quick and easy method to copy files using root authority even if remote root logins are disabled.  For this method to work, you will need the following setp:

 

  • SSH keys to all remote servers as a regular user.
  • sudo access to root as the regular user with the sudo "NOPASSWD" option.

 

Once this is done, you can use a combination of "cat", "sudo", and "ssh" to easily push out a file to mulitple servers with root authority.. 

 

Here is an example of pushing out a new resolv.conf file to all servers listed in the "serverlist" file:

 

for server in `cat serverlist`; do echo $server; cat resolv.conf | ssh -o "BatchMode yes" -q $server "sudo su -c 'cat - > /etc/resolv.conf'"; done

 

It works by catting the file to be transferred and pipping it to the SSH connection.  Within the SSH connection we sudo to root and then use cat to write the standard input to the file. 

This will also work with binary files - not just text files..

Modified on by brian_s 270002K5X3
  • Add a Comment Add a Comment
  • Edit
  • More Actions v
  • Quarantine this Entry
Notify Other People
notification

Send Email Notification

+

Quarantine this entry

deleteEntry
duplicateEntry

Mark as Duplicate

  • Previous Entry
  • Main
  • Next Entry
Feed for Blog Entries | Feed for Blog Comments | Feed for Comments for this Entry