Guest User

Untitled

a guest
Mar 12th, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. scp -r folder/ user@server.tld:/some/folder/you/dont/need/sudo
  2. ssh user@server.tld
  3. $ sudo mv /some/folder /some/folder/requiring/perms
  4. # YOU MAY NEED TO CHANGE THE OWNER like:
  5. # sudo chown -R user:user folder
  6.  
  7. tar -c -C ./my/local/dir
  8. | ssh dimitris@myserver.com "sudo tar -x --no-same-owner -C /var/www"
  9.  
  10. ansible -i HOST, -b -m copy -a "src=SRC_FILEPATH dest=DEST_FILEPATH" all
  11.  
  12. ansible -i HOST, -b -m fetch -a "src=SRC_FILEPATH dest=DEST_FILEPATH flat=yes" all
  13.  
  14. cd sourcedir &&
  15. ansible
  16. --inventory-file hostname,
  17. --become
  18. --become-method sudo
  19. --become-user root
  20. --module-name copy
  21. --args "src=. dest=/var/www/"
  22. all
  23.  
  24. cd sourcedir &&
  25. ansible -i hostname, -b -m copy -a "src=. dest=/var/www/" all
  26.  
  27. sudo chown -R dimitri:dimitri /home/dimitri
  28.  
  29. rsync -a --rsync-path="sudo -u www-data rsync" path_to_local_data/ login@srv01.example.com:/var/www
  30.  
  31. rsync -a --rsync-path="sudo rsync" path_to_local_data/ login@srv01.example.com:/var/www
  32.  
  33. ssh -R 11111:localhost:22 REMOTE_USERNAME@SERVERNAME
  34.  
  35. cd /var/www/
  36. sudo scp -P 11111 -r LOCAL_USERNAME@localhost:FOLDERNAME .
  37.  
  38. ssh user@server "sudo cat /etc/dir/file" > /home/user/file
  39.  
  40. touch /tmp/justtest && scpassudo /tmp/justtest remoteuser@ssh.superserver.com:/tmp/
  41.  
  42. interface=wlan0
  43. if [[ $# -ge 3 ]]; then interface=$3; fi
  44. thisIP=$(ifconfig | grep $interface -b1 | tail -n1 | egrep -o '[0-9.]{4,}' -m1 | head -n 1)
  45. thisUser=$(whoami)
  46. localFilePath=/tmp/justfortest
  47. destIP=192.168.0.2
  48. destUser=silesia
  49. #dest
  50. #destFolderOnRemoteMachine=/opt/glassfish/glassfish/
  51. #destFolderOnRemoteMachine=/tmp/
  52.  
  53. if [[ $# -eq 0 ]]; then
  54. echo -e "Send file to remote server to locatoin where root permision is needed.ntusage: $0 local_filename [username@](ip|host):(remote_folder/|remote_filename) [optionalInterface=wlan0]"
  55. echo -e "Example: nttouch /tmp/justtest &&nt $0 /tmp/justtest remoteuser@ssh.superserver.com:/tmp/ "
  56. exit 1
  57. fi
  58.  
  59. localFilePath=$1
  60.  
  61. test -e $localFilePath
  62.  
  63. destString=$2
  64. usernameAndHost=$(echo $destString | cut -f1 -d':')
  65.  
  66. if [[ "$usernameAndHost" == *"@"* ]]; then
  67. destUser=$(echo $usernameAndHost | cut -f1 -d'@')
  68. destIP=$(echo $usernameAndHost | cut -f2 -d'@')
  69. else
  70. destIP=$usernameAndHost
  71. destUser=$thisUser
  72. fi
  73.  
  74. destFolderOnRemoteMachine=$(echo $destString | cut -f2 -d':')
  75.  
  76. set -e #stop script if there is even single error
  77.  
  78. echo 'First step: we need to be able to execute scp without any user interaction'
  79. echo 'generating public key on machine, which will receive file'
  80. ssh $destUser@$destIP 'test -e ~/.ssh/id_rsa.pub -a -e ~/.ssh/id_rsa || ssh-keygen -t rsa'
  81. echo 'Done'
  82.  
  83. echo 'Second step: download public key from remote machine to this machine so this machine allows remote machine (this one receiveing file) to login without asking for password'
  84.  
  85. key=$(ssh $destUser@$destIP 'cat ~/.ssh/id_rsa.pub')
  86. if ! grep "$key" ~/.ssh/authorized_keys; then
  87. echo $key >> ~/.ssh/authorized_keys
  88. echo 'Added key to authorized hosts'
  89. else
  90. echo "Key already exists in authorized keys"
  91. fi
  92.  
  93. echo "We will want to execute sudo command remotely, which means turning off asking for password"
  94. echo 'This can be done by this tutorial http://stackoverflow.com/a/10310407/781312'
  95. echo 'This you have to do manually: '
  96. echo -e "execute in new terminal: ntssh $destUser:$destIPnPress enter when ready"
  97. read
  98. echo 'run there sudo visudo'
  99. read
  100. echo 'change '
  101. echo ' %sudo ALL=(ALL:ALL) ALL'
  102. echo 'to'
  103. echo ' %sudo ALL=(ALL:ALL) NOPASSWD: ALL'
  104. echo "After this step you will be done."
  105. read
  106.  
  107. listOfFiles=$(ssh $destUser@$destIP "sudo ls -a")
  108.  
  109. if [[ "$listOfFiles" != "" ]]; then
  110. echo "Sending by executing command, in fact, receiving, file on remote machine"
  111. echo 'Note that this command (due to " instead of '', see man bash | less -p''quotes'') is filled with values from local machine'
  112. echo -e "Executing nt""identy=~/.ssh/id_rsa; sudo scp -i $identy $(whoami)@$thisIP:$(readlink -f $localFilePath) $destFolderOnRemoteMachine"" non remote machine"
  113. ssh $destUser@$destIP "identy=~/.ssh/id_rsa; sudo scp -i $identy $(whoami)@$thisIP:$(readlink -f $localFilePath) $destFolderOnRemoteMachine"
  114. ssh $destUser@$destIP "ls ${destFolderOnRemoteMachine%\\n}/$(basename $localFilePath)"
  115. if [[ ! "$?" -eq 0 ]]; then echo "errror in validating"; else echo -e "SUCCESS! Successfully sentnt$localFilePath nto nt$destStringnFind more at http://arzoxadi.tk"; fi
  116. else
  117. echo "something went wrong with executing sudo on remote host, failure"
  118.  
  119. fi
  120. ENDOFSCRIPT
  121. ) | sudo tee /usr/bin/scpassudo && chmod +x /usr/bin/scpassudo
  122.  
  123. (stty -echo; read passwd; stty echo; echo $passwd; tar -cz foo.*)
  124. | ssh remote_host "sudo -S bash -c "tar -C /var/www/ -xz; echo""
  125.  
  126. (stty -echo; read passwd; stty echo; echo $passwd; tar -cz foo.*)
  127. | ssh remote_host "sudo -S bash -c "tar -C /var/www/ -xz; echo""
  128.  
  129. $ (stty -echo; read passwd; stty echo; echo $passwd; tar -cz foo.*) | ssh
  130. remote_host "sudo -S bash -c "tar -C /var/www/ -xz; echo""
  131. [sudo] password for bruce:
  132. [1]+ Stopped ( stty -echo; read passwd; stty echo; echo
  133. $passwd; tar -cz foo.* ) | ssh remote_host "sudo -S bash -c "tar -C
  134. /var/www/ -xz; echo""
  135.  
  136. $ pstree -lap $$
  137. bash,7168
  138. ├─bash,7969
  139. ├─pstree,7972 -lap 7168
  140. └─ssh,7970 remote_host sudo -S bash -c "tar -C /var/www/ -xz; echo"`
Add Comment
Please, Sign In to add comment