Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scp -r folder/ user@server.tld:/some/folder/you/dont/need/sudo
- ssh user@server.tld
- $ sudo mv /some/folder /some/folder/requiring/perms
- # YOU MAY NEED TO CHANGE THE OWNER like:
- # sudo chown -R user:user folder
- tar -c -C ./my/local/dir
- | ssh dimitris@myserver.com "sudo tar -x --no-same-owner -C /var/www"
- ansible -i HOST, -b -m copy -a "src=SRC_FILEPATH dest=DEST_FILEPATH" all
- ansible -i HOST, -b -m fetch -a "src=SRC_FILEPATH dest=DEST_FILEPATH flat=yes" all
- cd sourcedir &&
- ansible
- --inventory-file hostname,
- --become
- --become-method sudo
- --become-user root
- --module-name copy
- --args "src=. dest=/var/www/"
- all
- cd sourcedir &&
- ansible -i hostname, -b -m copy -a "src=. dest=/var/www/" all
- sudo chown -R dimitri:dimitri /home/dimitri
- rsync -a --rsync-path="sudo -u www-data rsync" path_to_local_data/ login@srv01.example.com:/var/www
- rsync -a --rsync-path="sudo rsync" path_to_local_data/ login@srv01.example.com:/var/www
- ssh -R 11111:localhost:22 REMOTE_USERNAME@SERVERNAME
- cd /var/www/
- sudo scp -P 11111 -r LOCAL_USERNAME@localhost:FOLDERNAME .
- ssh user@server "sudo cat /etc/dir/file" > /home/user/file
- touch /tmp/justtest && scpassudo /tmp/justtest remoteuser@ssh.superserver.com:/tmp/
- interface=wlan0
- if [[ $# -ge 3 ]]; then interface=$3; fi
- thisIP=$(ifconfig | grep $interface -b1 | tail -n1 | egrep -o '[0-9.]{4,}' -m1 | head -n 1)
- thisUser=$(whoami)
- localFilePath=/tmp/justfortest
- destIP=192.168.0.2
- destUser=silesia
- #dest
- #destFolderOnRemoteMachine=/opt/glassfish/glassfish/
- #destFolderOnRemoteMachine=/tmp/
- if [[ $# -eq 0 ]]; then
- 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]"
- echo -e "Example: nttouch /tmp/justtest &&nt $0 /tmp/justtest remoteuser@ssh.superserver.com:/tmp/ "
- exit 1
- fi
- localFilePath=$1
- test -e $localFilePath
- destString=$2
- usernameAndHost=$(echo $destString | cut -f1 -d':')
- if [[ "$usernameAndHost" == *"@"* ]]; then
- destUser=$(echo $usernameAndHost | cut -f1 -d'@')
- destIP=$(echo $usernameAndHost | cut -f2 -d'@')
- else
- destIP=$usernameAndHost
- destUser=$thisUser
- fi
- destFolderOnRemoteMachine=$(echo $destString | cut -f2 -d':')
- set -e #stop script if there is even single error
- echo 'First step: we need to be able to execute scp without any user interaction'
- echo 'generating public key on machine, which will receive file'
- ssh $destUser@$destIP 'test -e ~/.ssh/id_rsa.pub -a -e ~/.ssh/id_rsa || ssh-keygen -t rsa'
- echo 'Done'
- 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'
- key=$(ssh $destUser@$destIP 'cat ~/.ssh/id_rsa.pub')
- if ! grep "$key" ~/.ssh/authorized_keys; then
- echo $key >> ~/.ssh/authorized_keys
- echo 'Added key to authorized hosts'
- else
- echo "Key already exists in authorized keys"
- fi
- echo "We will want to execute sudo command remotely, which means turning off asking for password"
- echo 'This can be done by this tutorial http://stackoverflow.com/a/10310407/781312'
- echo 'This you have to do manually: '
- echo -e "execute in new terminal: ntssh $destUser:$destIPnPress enter when ready"
- read
- echo 'run there sudo visudo'
- read
- echo 'change '
- echo ' %sudo ALL=(ALL:ALL) ALL'
- echo 'to'
- echo ' %sudo ALL=(ALL:ALL) NOPASSWD: ALL'
- echo "After this step you will be done."
- read
- listOfFiles=$(ssh $destUser@$destIP "sudo ls -a")
- if [[ "$listOfFiles" != "" ]]; then
- echo "Sending by executing command, in fact, receiving, file on remote machine"
- echo 'Note that this command (due to " instead of '', see man bash | less -p''quotes'') is filled with values from local machine'
- echo -e "Executing nt""identy=~/.ssh/id_rsa; sudo scp -i $identy $(whoami)@$thisIP:$(readlink -f $localFilePath) $destFolderOnRemoteMachine"" non remote machine"
- ssh $destUser@$destIP "identy=~/.ssh/id_rsa; sudo scp -i $identy $(whoami)@$thisIP:$(readlink -f $localFilePath) $destFolderOnRemoteMachine"
- ssh $destUser@$destIP "ls ${destFolderOnRemoteMachine%\\n}/$(basename $localFilePath)"
- if [[ ! "$?" -eq 0 ]]; then echo "errror in validating"; else echo -e "SUCCESS! Successfully sentnt$localFilePath nto nt$destStringnFind more at http://arzoxadi.tk"; fi
- else
- echo "something went wrong with executing sudo on remote host, failure"
- fi
- ENDOFSCRIPT
- ) | sudo tee /usr/bin/scpassudo && chmod +x /usr/bin/scpassudo
- (stty -echo; read passwd; stty echo; echo $passwd; tar -cz foo.*)
- | ssh remote_host "sudo -S bash -c "tar -C /var/www/ -xz; echo""
- (stty -echo; read passwd; stty echo; echo $passwd; tar -cz foo.*)
- | ssh remote_host "sudo -S bash -c "tar -C /var/www/ -xz; echo""
- $ (stty -echo; read passwd; stty echo; echo $passwd; tar -cz foo.*) | ssh
- remote_host "sudo -S bash -c "tar -C /var/www/ -xz; echo""
- [sudo] password for bruce:
- [1]+ Stopped ( stty -echo; read passwd; stty echo; echo
- $passwd; tar -cz foo.* ) | ssh remote_host "sudo -S bash -c "tar -C
- /var/www/ -xz; echo""
- $ pstree -lap $$
- bash,7168
- ├─bash,7969
- ├─pstree,7972 -lap 7168
- └─ssh,7970 remote_host sudo -S bash -c "tar -C /var/www/ -xz; echo"`
Add Comment
Please, Sign In to add comment