Upload
deryarahmi-yildiz
View
33
Download
0
Embed Size (px)
Citation preview
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 1/14
Gotatip?Letusknow
Search
DiliSein eviritarafndandesteklenmektedir
AdvertiseLinuxServicesAboutArchivesContactUsCopyrightPolicyDonatetoTecMint
HomeLinuxDistrosInterviewQuestionsShellScriptingFreeLinuxeBooksLinuxCommandsTools
DidYouKnow?
LFCSLinuxFoundationCertifiedSysAdminExamPreparationGuide
10SCPCommandstoTransferFiles/FoldersinLinux
ByPungkiAriantoUnder:LinuxCommandsOn:October4,2013
DownloadYourFreeeBooksNOW10FreeLinuxeBooksforAdministrators
LinuxadministratorshouldbefamiliarwithCLIenvironment.SinceGUImodeinLinuxserversisnotacommontobeinstalled.SSHmaythemostpopularprotocoltoenableLinuxadministratortomanagetheserversviaremoteinsecureway.BuiltinwithSSHcommandthereisSCPcommand.SCPisusedtocopyfile(s)betweenserversinsecureway.
Key SCP SSHServer LinuxFree
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 2/14
10LinuxSCPCommands
Thebelowcommandwillreadascopysource_file_nameintodestination_folderatdestination_hostusingusernameaccount.
BasicsyntaxofSCP
scp source_file_name username@destination_host:destination_folder
TherearemuchparametersinSCPcommandthatyoucanuse.Herearetheparametersthatmayusefulondailybasisusage.
ProvidethedetailinformationofSCPprocessusingvparameter
BasicSCPcommandwithoutparameterwillcopythefilesinbackground.Userwillseenothingunlesstheprocessisdoneorsomeerrorappears.Youcanusevparametertoprintdebuginformationintothescreen.Itcanhelpyoudebuggingconnection,authenticationandconfigurationproblems.
pungki@mint ~/Documents $ scp -v Label.pdf [email protected]:.
SampleOutput
Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -t .OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012debug1: Reading configuration data /etc/ssh/ssh_configdebug1: /etc/ssh/ssh_config line 19: Applying options for *debug1: Connecting to 202.x.x.x [202.x.x.x] port 22.debug1: Connection established.debug1: Host '202.x.x.x' is known and matches the RSA host key.debug1: Found key in /home/pungki/.ssh/known_hosts:1debug1: ssh_rsa_verify: signature correctdebug1: Next authentication method: [email protected]'s password:debug1: Authentication succeeded (password).Authenticated to 202.x.x.x ([202.x.x.x]:22).Sending file modes: C0770 3760348 Label.pdfSink: C0770 3760348 Label.pdfLabel.pdf 100% 3672KB 136.0KB/s 00:27Transferred: sent 3766304, received 3000 bytes, in 65.2 secondsBytes per second: sent 57766.4, received 46.0debug1: Exit status 0
Providemodificationtimes,accesstimes,andmodesfromoriginalfiles
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 3/14
Thepparameterwillhelpyouonthis.Anestimatedtimeandtheconnectionspeedwillappearonthescreen.
pungki@mint ~/Documents $ scp -p Label.pdf [email protected]:.
SampleOutput
[email protected]'s password:Label.pdf 100% 3672KB 126.6KB/s 00:29
MakefiletransferfasterusingCparameter
OneofparameterthatcanfasteryourfiletransferisCparameter.TheCparameterwillcompressyourfilesonthego.Theuniquethingisthecompressionisonlyhappeninthenetwork.Whenthefileisarrivedtothedestinationserver,itwillreturningintotheoriginalsizeasbeforethecompressionhappen.
Takealookofthesecommands.Itisusingasinglefileof93Mb.
pungki@mint ~/Documents $ scp -pv messages.log [email protected]:.
SampleOutput
Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -p -t .OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012debug1: Reading configuration data /etc/ssh/ssh_configdebug1: /etc/ssh/ssh_config line 19: Applying options for *debug1: Connecting to 202.x.x.x [202.x.x.x] port 22.debug1: Connection established.debug1: identity file /home/pungki/.ssh/id_rsa type -1debug1: Found key in /home/pungki/.ssh/known_hosts:1debug1: ssh_rsa_verify: signature correctdebug1: Trying private key: /home/pungki/.ssh/id_rsadebug1: Next authentication method: [email protected]'s password:debug1: Authentication succeeded (password).Authenticated to 202.x.x.x ([202.x.x.x]:22).debug1: Sending command: scp -v -p -t .File mtime 1323853868 atime 1380425711Sending file timestamps: T1323853868 0 1380425711 0messages.log 100% 93MB 58.6KB/s 27:05Transferred: sent 97614832, received 25976 bytes, in 1661.3 secondsBytes per second: sent 58758.4, received 15.6debug1: Exit status 0
CopyingfilewithoutCparameterwillresult1661.3second.YomaycomparetheresulttothecommandbelowwhichusingCparameter.
pungki@mint ~/Documents $ scp -Cpv messages.log [email protected]:.
SampleOutput
Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -p -t .OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012debug1: Reading configuration data /etc/ssh/ssh_configdebug1: /etc/ssh/ssh_config line 19: Applying options for *debug1: Connecting to 202.x.x.x [202.x.x.x] port 22.debug1: Connection established.debug1: identity file /home/pungki/.ssh/id_rsa type -1debug1: Host '202.x.x.x' is known and matches the RSA host key.debug1: Found key in /home/pungki/.ssh/known_hosts:1debug1: ssh_rsa_verify: signature correctdebug1: Next authentication method: publickeydebug1: Trying private key: /home/pungki/.ssh/id_rsadebug1: Next authentication method: [email protected]'s password:debug1: Enabling compression at level 6.
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 4/14
debug1: Authentication succeeded (password).Authenticated to 202.x.x.x ([202.x.x.x]:22).debug1: channel 0: new [client-session]debug1: Sending command: scp -v -p -t .File mtime 1323853868 atime 1380428748Sending file timestamps: T1323853868 0 1380428748 0Sink: T1323853868 0 1380428748 0Sending file modes: C0600 97517300 messages.logmessages.log 100% 93MB 602.7KB/s 02:38Transferred: sent 8905840, received 15768 bytes, in 162.5 secondsBytes per second: sent 54813.9, received 97.0debug1: Exit status 0debug1: compress outgoing: raw data 97571111, compressed 8806191, factor 0.09debug1: compress incoming: raw data 7885, compressed 3821, factor 0.48
Asyoucansee,whenyouareusingcompression,transferprocessisdonein162.5second.Itis10timesfasterthannotusingCparameter.Ifyouarecopyingalotfilesacrossthenetwork,Cparameterwouldhelpyoutodecreasethetotaltimeyouneed.
Thethingthatweshouldnoticethatcompressionmethodwillnotworkonanyfiles.Whenthesourcefileisalreadycompressed,youwillnotfindanyimprovementthere.Filessuchas.zip,.rar,pictures,and.isofileswillnotaffectedbyCparameter.
Selectanotherciphertoencryptfiles
BydefaultSCPusingAES128toencryptfiles.Ifyouwanttochangetoanotherciphertoencryptit,youcanusecparameter.Takealookofthiscommand.
pungki@mint ~/Documents $ scp -c 3des Label.pdf [email protected]:.
[email protected]'s password:Label.pdf 100% 3672KB 282.5KB/s 00:13
AbovecommandtellSCPtouse3desalgorithmtoencryptfile.PleasebecarefulthatthisparameterusingcnotC.
Limitingbandwidthusage
Anotherparameterthatmayusefulislparameter.Thelparameterwilllimitthebandwidthtouse.Itwillbeusefulifyoudoanautomationscripttocopyalotoffile,butyoudontwantthebandwidthisdrainedbytheSCPprocess.
pungki@mint ~/Documents $ scp -l 400 Label.pdf [email protected]:.
[email protected]'s password:Label.pdf 100% 3672KB 50.3KB/s 01:13
The400valuebehindlparameterismeanthatwelimitthebandwidthforSCPprocessonly50KB/sec.OnethingtorememberthatbandwidthisspecifiedinKilobits/sec(kbps).Itismeanthat8bitsequalwith1byte.
WhileSCPcountsinKilobyte/sec(KB/s).SoifyouwanttolimityourbandwidthforSCPmaximumonly50KB/s,youneedtosetitinto50x8=400.
SpecifyspecificporttousewithSCP
UsuallySCPisusingport22asadefaultport.Butforsecurityreason,youmaychangetheportintoanotherport.Forexample,weareusingport2249.Thenthecommandshouldbelikethis.
pungki@mint ~/Documents $ scp -P 2249 Label.pdf [email protected]:.
[email protected]'s password:Label.pdf 100% 3672KB 262.3KB/s 00:14
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 5/14
MakesurethatitusecapitalPnotp,sincepisalreadyusedforpreservedtimesandmodes.
Copyfilesinsidedirectoryrecursively
Sometimesweneedtocopydirectoryandallfiles/directoriesinsideit.Itwillbebetterifwecandoitin1command.SCPsupportthatscenariousingrparameter.
pungki@mint ~/Documents $ scp -r documents [email protected]:.
[email protected]'s password:Label.pdf 100% 3672KB 282.5KB/s 00:13scp.txt 100% 10KB 9.8KB/s 00:00
Whenthecopyprocessisdone,atthedestinationserveryouwillfoundadirectorynameddocumentswithallitsfiles.Thefolderdocumentsisautomaticallycreated.
Disableprogressmeterandwarning/diagnosticmessage
Ifyouchoosenottoseeprogressmeterandwarning/diagnosticmessagesfromSCP,youmaydisableitusingqparameter.Herestheexample.
pungki@mint ~/Documents $ scp -q Label.pdf [email protected]:.
[email protected]'s password:pungki@mint ~/Documents $
Asyoucansee,aftertheyouenterthepassword,thereisnoanyinformationaboutSCPprocess.Aftertheprocessiscomplete,youwillbeseeapromptagain.
CopyfilesusingSCPthroughProxy
Proxyserverisusuallyusedinofficeenvironment.Natively,SCPisnotproxyconfigured.Whenyourenvironmentusingproxy,youhavetotellSCPtocommunicatewiththeproxy.
Heresthescenario.Theproxyaddressis10.0.96.6andtheproxyportis8080.Theproxyalsoimplementeduserauthentication.First,youneedtocreate~/.ssh/configfile.Secondyouputthiscommandinsideit.
ProxyCommand /usr/bin/corkscrew 10.0.96.6 8080 %h %p ~/.ssh/proxyauth
Thenyouneedtocreatefile~/.ssh/proxyauthwhichcontain.
myusername:mypassword
AfterthatyoucandoSCPtransparentlyasusual.
Pleasenoticethatcorkscrewismightnotinstalledyetonyoursystem.OnmyLinuxMint,Ineedtoinstallitfirst,usingstandardLinuxMintinstallationprocedure.
$ apt-get install corkscrew
Forotheryumbasedsystems,userscaninstallcorkscrewusingthefollowingyumcommand.
# yum install corkscrew
Anotherthingthatsince~/.ssh/proxyauthfilecontainyourusernameandpasswordincleartextformat,pleasemakesurethatthefilecanbeaccessedbyyouonly.
Selectdifferentssh_configfile
Formobileuserwhooftenswitchbetweencompanynetworkandpublicnetwork,itwillbesuffertoalwayschangesettingsinSCP.Itisbetterifwecanputadifferentssh_configfiletomatchourneeds.
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 6/14
Bio LatestPosts
Heresasamplescenario
Proxyisusedincompanynetworkbutnotinpublicnetworkandyouareregularlyswitchnetwork.
pungki@mint ~/Documents $ scp -F /home/pungki/proxy_ssh_config Label.pdf
[email protected]:[email protected]'s password:Label.pdf 100% 3672KB 282.5KB/s 00:13
Bydefaultssh_configfileperuserwillbeplacedin~/.ssh/config.Creatingaspecificssh_configfilewithproxycompatible,willmakeyoueasiertoswitchbetweennetworks.
Whenyouareoncompanynetwork,youcanuseFparameter.Whenyouareonpublicnetwork,youcanskipFparameter.
ThatsallaboutSCP.YoucanseemanpagesofSCPformoredetail.Pleasefeelfreetoleavecommentsandsuggestions.
PungkiArianto
CurrentlyIamaLinux/Unixadministrator.ButIalsoplayWindowsbothinserveranddesktoparea.Interestedininformationtechnology,informationsecurityandwriting.
DownloadFreeeBooks
Tweet
39
362
24
comments
PreviousPost
15PracticalExamplesofdpkgcommandsforDebianBasedDistros
NextPost
MuttACommandLineEmailClienttoSendMailsfromTerminal
RelatedPost(s):
12
Share
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 7/14
1. 35PracticalExamplesofLinuxFindCommand2. 29PracticalExamplesofNmapCommandsforLinuxSystem/NetworkAdministrators3. 8PraticalExamplesofLinuxTouchCommand4. TheCompleteGuidetouseraddCommandinLinux15PracticalExamples5. HowtoStopandDisableUnwantedServicesfromLinuxSystem6. 10LesserKnownCommandsforLinuxPart3
24Responses
Kamisays:1. October5,2013at3:04am
Thanks,greatandvaluablesummary.
Reply
RoseHosting.comsays:2. October5,2013at6:27pm
nicewriteuponmostcommonscpusageexamples.itwillsurelybeusefultoanyonelookingonhowtousescp.
toaddtoit,onecanalsousescptoedit/createfilesremotelyusingvim+scp.forexample,toedit/etc/hostsonaremoteserverwheresshislisteningonport8822onecando:
vimscp://root@:8822//etc/hosts
ifsshisonitsdefaultport22thenthe:8822partcanbeomitted
itcomeshandysometimessoIthoughtwillshareitwithyou)
Reply
PungkiAriantosays:October8,2013at2:12pm
Thankyouforyourshare.Itishandy:)
Reply
3. Rahulsays:October6,2013at7:48am
compressoptionmostusefultomeasitransferlotoffilesthatcouldbecompressed.
Reply
PungkiAriantosays:October8,2013at1:22pm
Thankyou.Nicetoseethisarticlecanbeuseful
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 8/14
Reply
4. Johnsays:October6,2013at11:03am
Itsworthnotingthatrsyncwillhappilycopyoversshandwillthereforedoalloftheabovewiththesamesecuritybutwithmuchmorepowerfulcopyingoptions.
Reply
marksays:November20,2014at1:36am
Andrsyncwillalsocopyhiddenfileswhilescpdoesnot
Reply
5. HkonNsays:October6,2013at4:50pm
WhileSCPcountsinKilobyte/sec(KB/s).SoifyouwanttolimityourbandwidthforSCPmaximumonly50KB/s,youneedtosetitinto50x8=400.
SCPcountsinkilobits,youmean.Kb/s.Otherwiseyouwouldnthavetomultiply..
Reply
PungkiAriantosays:October8,2013at2:10pm
Yes.Itwasmymistake.ImeanSCPcountinkilobits.IcrosscheckedwithSCPmanualpages.Thankyou
Reply
6. HkonNsays:October6,2013at4:52pm
SCPdisplaysthespeedinKB/swouldbebettertosay.Youshouldclearifyitmorethattheparameterexpectsbits,butitdisplaysinbytes..
Reply
7. mariosays:November16,2013at5:39am
Thanksalotveryuseful!Keepwriting,please!
Reply
PungkiAriantosays:November19,2013at12:02am
Thankyouverymuch.
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 9/14
Reply
8. Aktarsays:January27,2014at10:59am
ThanksalotfortheinfoItsveryuseful.
Reply
9. Aktarsays:January27,2014at11:03am
Justwantedtoknowindetailhowwecanusedifferentconfigfile.Wouldbereallygreatifyouprovidethedetaileddescription.
Reply
10. Nitinsays:February26,2014at3:35pm
Hi,Thanksforsharingimportantinformation,buthoweveritdoesnotsolvemyproblem.
Ihaveonebackupserverandonemainftpserver.Ihavetoexecuteascriptfrombackupservertomovethefilesfromapath1onmainftpservertoanotherpath2onthesamemainftpserver.Icannotusesshforthis.
Canyousuggestmehowcaniperformthis??
Anyinformationandguidancewillbeappreciable.
Thanksagainfortheinformation.
Reply
11. Adnsays:March31,2014at12:56am
Thisisaterrificpost!Ithelpedmetobackupallofmydatafrommypreviouscomputertomynewone.Thescprandyoujustsavedmealotofmoney!Haha
ThankyousomuchandkeepgoingonsharingallofthishelpfulstufftoalltheLinuxcommunity.
Reply
12. Willsays:April10,2014at12:30am
Incrediblyusefulstuff.Thanksomuchforpublishing.Cisalifesaver!
Reply
13. MarkChamberssays:April14,2014at1:29pm
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 10/14
Excellentwriteup.Veryhelpful.Thankyou!ButthelocaluserdirectoryonMacOSXwasntbeingrecognizedforme.Itkeptthrowingmeanosuchdirectoryerror.Icouldonlygetittofindafolderinmyrootdirectory,butthetransferbrokeoffandnothingwasactuallycopied,possilbyduetopermissionsaccessingarootdirectory,forwhichIneededapasswordjusttocreateanewfolder.Anysuggestions?
Mycommandwasasfollows,forcopyingremotetolocal:scpprCroot@lvps17877101202:/var/www/vhosts~/Downloads/ppcombackup
Reply
14. TonyKellersays:July23,2014at12:59am
WhatisthepathsyntaxforcopyingafilefromaLinuxboxtoaWindowsbox?Iwillhaveakeysomycommandwouldlike:
scp$FILE_HOME/${CSV1}svc_usercopy@$job_server:D:\KronosMasterFileDirectory\Employees\EmployeesImport.csv
IdontknowiftheLinuxservercareswhattheWindowsdirectorylookslikeornot.Anyideasonhowthisshouldlook?
Reply
RaviSaivesays:July23,2014at3:26pm
Noidea,neverevertriedthis.
Reply
15. Jagdishkumarsays:July31,2014at2:38pm
Hi,
IjustwanttosayyouAllguysforsharinghelpfulinformation.Pleasekeepitupsowecanlearnalot:):)
Reply
16. Guilhermesays:August1,2014at12:59pm
Ialsowanttoletyouknowhowthiswashelpfulforme!
Reply
17. MrGenkisays:August25,2014at11:08am
ISSHedintomyiphone,andattemptedtocopyafileontolocalhost.Whenaskedforapassword,ienteredmypasswordiusetologintothelocalhost,howeverigetapasswordincorrecterror.anysuggestions?
Reply
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 11/14
18. GauravGuptasays:September22,2014at7:36pm
Helpfulblog
Reply
LeaveaReply
Name(Required)
Mail(willnotbepublished)(Required)
Website
SubmitComment
Twitter1838TwitterFacebook42041FacebookGoogle+8004Google+RSS3861Subscribers
BecomeATecMintSubscribertoreceivelatestUpdates.EnterYourEmailAddress:) Signup!
PopularLatestComments
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 12/14
Tags
HowtoAddLinuxHosttoNagiosMonitoringServerUsingNRPEPlugin239Comments
Nagios4.0.1ReleasedInstallonRHEL/CentOS6.x/5.xandFedora19/18/17190Comments
CentOS6.4StepbyStepInstallationGuidewithScreenshots175Comments
Wine1.6.2StableReleasedInstallinRHEL,CentOSandFedora171Comments
InstallApache2.2.15,MySQL5.5.34&PHP5.5.4onRHEL/CentOS6.4/5.9&Fedora1912165Comments
GoogleChrome39ReleasedInstallonRHEL/CentOS7/6andFedora2015160Comments
::Advertise::
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 13/14
::DownloadFreeLinuxeBooks::
CompleteLinuxCommandLineCheatSheetTheGNU/LinuxAdvancedAdministrationGuideSecuring&OptimizingLinuxServersLinuxPatchManagement:KeepingLinuxUpToDateIntroductiontoLinuxAHandsonGuideUnderstandingtheLinuxVirtualMemoryManagerLinuxBiblePackedwithUpdatesandExercisesANewbiesGettingStartedGuidetoLinuxLinuxfromScratchCreateYourOwnLinuxOSLinuxShellScriptingCookbook,SecondEditionSecuring&OptimizingLinux:TheHackingSolutionUserModeLinuxUnderstandingandAdministration
::FollowUs::
21.11.2014 10 SCP Commands to Transfer Files/Folders in Linux
http://www.tecmint.com/scp-commands-examples/ 14/14
KnowMore
SubmitOrder
AdvertiseNow
TecMint.comgoogle.com/+Tecmint
Tecmint: Linux Howtos, Tutorials & Guides
+ 9.033
2 evre +1
::About::
TecMint.comisawebsitethatpublishespracticalandusefuloutoftheboxarticlesforaspirantlikeyouandme.Weseektopresentexceptional,remarkabletips,tutorials,andresourcesthatthemodernwebprofessionalwillappreciate.
::OurServices::
WeofferwiderangeofLinuxWebHostingandManagementServicesincludesLinuxhosting,WordPresshosting,JoomlaHosting,CMShosting,WebsitemigrationandCustomsolutions,makingusaonestopdestinationforallyourpossiblehostingneedsatfairminimumrates.
::Advertise::
TecMint.comisvisitedbytensofthousandsofLinuxusersandhasaexcellentreputationinthesearchengineranking.MostofthetrafficcomesfromGoogleorganicsearch(80%).Spreadyourmessagesorproductstoanengagedreadersbyadvertisingwithus.
Thisworkislicensedundera(cc)BYNC|TecMintusescookies.Byusingourservices,youcomplytouseofourcookies.Moreinfo:PrivacyPolicy.20122014AllRightsReserved.
10UsefulFreeLinuxeBooksforNewbiesandAdministrators25HardeningSecurityTipsforLinuxServers60CommandsofLinux:AGuidefromNewbiestoSystemAdministrator15CommandLineToolstoMonitorLinuxPerformance5BestPracticestoSecureandProtectSSHServer18TarCommandExamplesinLinux20LinuxYUM(YellowdogUpdater,Modified)Commands25UsefulBasicCommandsofAPTGETandAPTCACHE20FunnyCommandsofLinuxorLinuxisFuninTerminal35PracticalExamplesofLinuxFindCommand10LinuxDistributionsandTheirTargetedUsers