Académique Documents
Professionnel Documents
Culture Documents
2014
Advertise
LinuxServices
About
Archives
ContactUs
CopyrightPolicy
DonatetoTecMint
Search
Home
LinuxDistros
InterviewQuestions
ShellScripting
FreeLinuxeBooks
LinuxCommands
Tools
DiliSein
eviritarafndandesteklenmektedirDidYouKnow?
LFCSLinuxFoundationCertifiedSysAdminExamPreparationGuide
Gotatip?Letusknow
10SCPCommandstoTransferFiles/FoldersinLinux
ByPungkiAriantoUnder:LinuxCommandsOn:October4,2013
Key
SCP
SSHServer LinuxFree
DownloadYourFreeeBooksNOW10FreeLinuxeBooksforAdministrators
LinuxadministratorshouldbefamiliarwithCLIenvironment.SinceGUImodeinLinuxserversisnota
commontobeinstalled.SSHmaythemostpopularprotocoltoenableLinuxadministratortomanagethe
serversviaremoteinsecureway.BuiltinwithSSHcommandthereisSCPcommand.SCPisusedtocopy
file(s)betweenserversinsecureway.
http://www.tecmint.com/scp-commands-examples/
1/14
21.11.2014
10LinuxSCPCommands
Thebelowcommandwillreadascopysource_file_nameintodestination_folderatdestination_host
usingusernameaccount.
BasicsyntaxofSCP
scp source_file_name username@destination_host:destination_folder
TherearemuchparametersinSCPcommandthatyoucanuse.Herearetheparametersthatmayusefulondaily
basisusage.
ProvidethedetailinformationofSCPprocessusingvparameter
BasicSCPcommandwithoutparameterwillcopythefilesinbackground.Userwillseenothingunlessthe
processisdoneorsomeerrorappears.Youcanusevparametertoprintdebuginformationintothescreen.It
canhelpyoudebuggingconnection,authenticationandconfigurationproblems.
pungki@mint ~/Documents $ scp -v Label.pdf mrarianto@202.x.x.x:.
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 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /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:1
debug1: ssh_rsa_verify: signature correct
debug1: Next authentication method: password
mrarianto@202.x.x.x's password:
debug1: Authentication succeeded (password).
Authenticated to 202.x.x.x ([202.x.x.x]:22).
Sending file modes: C0770 3760348 Label.pdf
Sink: C0770 3760348 Label.pdf
Label.pdf 100% 3672KB 136.0KB/s 00:27
Transferred: sent 3766304, received 3000 bytes, in 65.2 seconds
Bytes per second: sent 57766.4, received 46.0
debug1: Exit status 0
Providemodificationtimes,accesstimes,andmodesfromoriginalfiles
http://www.tecmint.com/scp-commands-examples/
2/14
21.11.2014
Thepparameterwillhelpyouonthis.Anestimatedtimeandtheconnectionspeedwillappearonthescreen.
pungki@mint ~/Documents $ scp -p Label.pdf mrarianto@202.x.x.x:.
SampleOutput
mrarianto@202.x.x.x's password:
Label.pdf 100% 3672KB 126.6KB/s 00:29
MakefiletransferfasterusingCparameter
OneofparameterthatcanfasteryourfiletransferisCparameter.TheCparameterwillcompressyour
filesonthego.Theuniquethingisthecompressionisonlyhappeninthenetwork.Whenthefileisarrivedto
thedestinationserver,itwillreturningintotheoriginalsizeasbeforethecompressionhappen.
Takealookofthesecommands.Itisusingasinglefileof93Mb.
pungki@mint ~/Documents $ scp -pv messages.log mrarianto@202.x.x.x:.
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 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /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 -1
debug1: Found key in /home/pungki/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: Trying private key: /home/pungki/.ssh/id_rsa
debug1: Next authentication method: password
mrarianto@202.x.x.x'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 1380425711
Sending file timestamps: T1323853868 0 1380425711 0
messages.log 100% 93MB 58.6KB/s 27:05
Transferred: sent 97614832, received 25976 bytes, in 1661.3 seconds
Bytes per second: sent 58758.4, received 15.6
debug1: Exit status 0
CopyingfilewithoutCparameterwillresult1661.3second.Yomaycomparetheresulttothecommand
belowwhichusingCparameter.
pungki@mint ~/Documents $ scp -Cpv messages.log mrarianto@202.x.x.x:.
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 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /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 -1
debug1: Host '202.x.x.x' is known and matches the RSA host key.
debug1: Found key in /home/pungki/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: Next authentication method: publickey
debug1: Trying private key: /home/pungki/.ssh/id_rsa
debug1: Next authentication method: password
mrarianto@202.x.x.x's password:
debug1: Enabling compression at level 6.
http://www.tecmint.com/scp-commands-examples/
3/14
21.11.2014
Asyoucansee,whenyouareusingcompression,transferprocessisdonein162.5second.Itis10timesfaster
thannotusingCparameter.Ifyouarecopyingalotfilesacrossthenetwork,Cparameterwouldhelpyou
todecreasethetotaltimeyouneed.
Thethingthatweshouldnoticethatcompressionmethodwillnotworkonanyfiles.Whenthesourcefileis
alreadycompressed,youwillnotfindanyimprovementthere.Filessuchas.zip,.rar,pictures,and.isofiles
willnotaffectedbyCparameter.
Selectanotherciphertoencryptfiles
BydefaultSCPusingAES128toencryptfiles.Ifyouwanttochangetoanotherciphertoencryptit,youcan
usecparameter.Takealookofthiscommand.
pungki@mint ~/Documents $ scp -c 3des Label.pdf mrarianto@202.x.x.x:.
mrarianto@202.x.x.x's password:
Label.pdf 100% 3672KB 282.5KB/s 00:13
AbovecommandtellSCPtouse3desalgorithmtoencryptfile.Pleasebecarefulthatthisparameterusingc
notC.
Limitingbandwidthusage
Anotherparameterthatmayusefulislparameter.Thelparameterwilllimitthebandwidthtouse.Itwill
beusefulifyoudoanautomationscripttocopyalotoffile,butyoudontwantthebandwidthisdrainedbythe
SCPprocess.
pungki@mint ~/Documents $ scp -l 400 Label.pdf mrarianto@202.x.x.x:.
mrarianto@202.x.x.x's password:
Label.pdf 100% 3672KB 50.3KB/s 01:13
The400valuebehindlparameterismeanthatwelimitthebandwidthforSCPprocessonly50KB/sec.One
thingtorememberthatbandwidthisspecifiedinKilobits/sec(kbps).Itismeanthat8bitsequalwith1byte.
WhileSCPcountsinKilobyte/sec(KB/s).SoifyouwanttolimityourbandwidthforSCPmaximumonly50
KB/s,youneedtosetitinto50x8=400.
SpecifyspecificporttousewithSCP
UsuallySCPisusingport22asadefaultport.Butforsecurityreason,youmaychangetheportintoanother
port.Forexample,weareusingport2249.Thenthecommandshouldbelikethis.
pungki@mint ~/Documents $ scp -P 2249 Label.pdf mrarianto@202.x.x.x:.
mrarianto@202.x.x.x's password:
Label.pdf 100% 3672KB 262.3KB/s 00:14
http://www.tecmint.com/scp-commands-examples/
4/14
21.11.2014
MakesurethatitusecapitalPnotp,sincepisalreadyusedforpreservedtimesandmodes.
Copyfilesinsidedirectoryrecursively
Sometimesweneedtocopydirectoryandallfiles/directoriesinsideit.Itwillbebetterifwecandoitin1
command.SCPsupportthatscenariousingrparameter.
pungki@mint ~/Documents $ scp -r documents mrarianto@202.x.x.x:.
mrarianto@202.x.x.x's password:
Label.pdf 100% 3672KB 282.5KB/s 00:13
scp.txt 100% 10KB 9.8KB/s 00:00
Whenthecopyprocessisdone,atthedestinationserveryouwillfoundadirectorynameddocumentswith
allitsfiles.Thefolderdocumentsisautomaticallycreated.
Disableprogressmeterandwarning/diagnosticmessage
Ifyouchoosenottoseeprogressmeterandwarning/diagnosticmessagesfromSCP,youmaydisableitusing
qparameter.Herestheexample.
pungki@mint ~/Documents $ scp -q Label.pdf mrarianto@202.x.x.x:.
mrarianto@202.x.x.x's password:
pungki@mint ~/Documents $
Asyoucansee,aftertheyouenterthepassword,thereisnoanyinformationaboutSCPprocess.Afterthe
processiscomplete,youwillbeseeapromptagain.
CopyfilesusingSCPthroughProxy
Proxyserverisusuallyusedinofficeenvironment.Natively,SCPisnotproxyconfigured.Whenyour
environmentusingproxy,youhavetotellSCPtocommunicatewiththeproxy.
Heresthescenario.Theproxyaddressis10.0.96.6andtheproxyportis8080.Theproxyalsoimplemented
userauthentication.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,Ineedtoinstallit
first,usingstandardLinuxMintinstallationprocedure.
$ apt-get install corkscrew
Forotheryumbasedsystems,userscaninstallcorkscrewusingthefollowingyumcommand.
# yum install corkscrew
Anotherthingthatsince~/.ssh/proxyauthfilecontainyourusernameandpasswordincleartext
format,pleasemakesurethatthefilecanbeaccessedbyyouonly.
Selectdifferentssh_configfile
Formobileuserwhooftenswitchbetweencompanynetworkandpublicnetwork,itwillbesuffertoalways
changesettingsinSCP.Itisbetterifwecanputadifferentssh_configfiletomatchourneeds.
http://www.tecmint.com/scp-commands-examples/
5/14
21.11.2014
Heresasamplescenario
Proxyisusedincompanynetworkbutnotinpublicnetworkandyouareregularlyswitchnetwork.
pungki@mint ~/Documents $ scp -F /home/pungki/proxy_ssh_config Label.pdf
mrarianto@202.x.x.x:.
mrarianto@202.x.x.x's password:
Label.pdf 100% 3672KB 282.5KB/s 00:13
Bydefaultssh_configfileperuserwillbeplacedin~/.ssh/config.Creatingaspecificssh_configfile
withproxycompatible,willmakeyoueasiertoswitchbetweennetworks.
Whenyouareoncompanynetwork,youcanuseFparameter.Whenyouareonpublicnetwork,youcan
skipFparameter.
ThatsallaboutSCP.YoucanseemanpagesofSCPformoredetail.Pleasefeelfreetoleavecommentsand
suggestions.
Bio
LatestPosts
PungkiArianto
CurrentlyIamaLinux/Unixadministrator.ButIalsoplayWindowsbothinserverand
desktoparea.Interestedininformationtechnology,informationsecurityandwriting.
DownloadFreeeBooks
39
Tweet
362
12
Share
24
comments
PreviousPost
15PracticalExamplesofdpkgcommandsforDebianBasedDistros
NextPost
MuttACommandLineEmailClienttoSendMailsfromTerminal
RelatedPost(s):
http://www.tecmint.com/scp-commands-examples/
6/14
21.11.2014
1. 35PracticalExamplesofLinuxFindCommand
2. 29PracticalExamplesofNmapCommandsforLinuxSystem/NetworkAdministrators
3. 8PraticalExamplesofLinuxTouchCommand
4. TheCompleteGuidetouseraddCommandinLinux15PracticalExamples
5. HowtoStopandDisableUnwantedServicesfromLinuxSystem
6. 10LesserKnownCommandsforLinuxPart3
24Responses
Kamisays:
1. October5,2013at3:04am
Thanks,greatandvaluablesummary.
Reply
RoseHosting.comsays:
2. October5,2013at6:27pm
nicewriteuponmostcommonscpusageexamples.itwillsurelybeusefultoanyonelookingonhowto
usescp.
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
scpCpvmessages.logmrarianto@202.x.x.x:.
compressoptionmostusefultomeasitransferlotoffilesthatcouldbecompressed.
Reply
PungkiAriantosays:
October8,2013at1:22pm
Thankyou.Nicetoseethisarticlecanbeuseful
http://www.tecmint.com/scp-commands-examples/
7/14
21.11.2014
Reply
4.
Johnsays:
October6,2013at11:03am
Itsworthnotingthatrsyncwillhappilycopyoversshandwillthereforedoalloftheabovewiththe
samesecuritybutwithmuchmorepowerfulcopyingoptions.
Reply
marksays:
November20,2014at1:36am
Andrsyncwillalsocopyhiddenfileswhilescpdoesnot
Reply
5.
HkonNsays:
October6,2013at4:50pm
WhileSCPcountsinKilobyte/sec(KB/s).SoifyouwanttolimityourbandwidthforSCPmaximum
only50KB/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.Youshouldclearifyitmorethattheparameter
expectsbits,butitdisplaysinbytes..
Reply
7.
mariosays:
November16,2013at5:39am
Thanksalotveryuseful!Keepwriting,please!
Reply
PungkiAriantosays:
November19,2013at12:02am
Thankyouverymuch.
http://www.tecmint.com/scp-commands-examples/
8/14
21.11.2014
Reply
8.
Aktarsays:
January27,2014at10:59am
Thanksalotfortheinfo
Itsveryuseful.
Reply
9.
Aktarsays:
January27,2014at11:03am
Justwantedtoknowindetailhowwecanusedifferentconfigfile.
Wouldbereallygreatifyouprovidethedetaileddescription.
Reply
10.
Nitinsays:
February26,2014at3:35pm
Hi,
Thanksforsharingimportantinformation,buthoweveritdoesnotsolvemyproblem.
Ihaveonebackupserverandonemainftpserver.Ihavetoexecuteascriptfrombackupservertomove
thefilesfromapath1onmainftpservertoanotherpath2onthesamemainftpserver.Icannotusessh
forthis.
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
http://www.tecmint.com/scp-commands-examples/
9/14
21.11.2014
Excellentwriteup.Veryhelpful.Thankyou!ButthelocaluserdirectoryonMacOSXwasntbeing
recognizedforme.Itkeptthrowingmeanosuchdirectoryerror.Icouldonlygetittofindafolderin
myrootdirectory,butthetransferbrokeoffandnothingwasactuallycopied,possilbyduetopermissions
accessingarootdirectory,forwhichIneededapasswordjusttocreateanewfolder.Anysuggestions?
Mycommandwasasfollows,forcopyingremotetolocal:scpprCroot@lvps17877101
202:/var/www/vhosts~/Downloads/ppcombackup
Reply
14.
TonyKellersays:
July23,2014at12:59am
WhatisthepathsyntaxforcopyingafilefromaLinuxboxtoaWindowsbox?Iwillhaveakeysomy
commandwouldlike:
scp$FILE_HOME/${CSV1}svc_usercopy@$job_server:D:\KronosMasterFile
Directory\Employees\EmployeesImport.csv
IdontknowiftheLinuxservercareswhattheWindowsdirectorylookslikeornot.Anyideasonhow
thisshouldlook?
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,i
enteredmypasswordiusetologintothelocalhost,howeverigetapasswordincorrecterror.any
suggestions?
Reply
http://www.tecmint.com/scp-commands-examples/
10/14
21.11.2014
18.
GauravGuptasays:
September22,2014at7:36pm
Helpfulblog
Reply
LeaveaReply
Name(Required)
Mail(willnotbepublished)(Required)
Website
SubmitComment
Twitter1838Twitter
Facebook42041Facebook
Google+8004Google+
RSS3861Subscribers
BecomeATecMintSubscribertoreceivelatestUpdates.
EnterYourEmailAddress:) Signup!
Popular
Latest
Comments
http://www.tecmint.com/scp-commands-examples/
11/14
21.11.2014
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&Fedora1912165
Comments
GoogleChrome39ReleasedInstallonRHEL/CentOS7/6andFedora2015160Comments
::Advertise::
http://www.tecmint.com/scp-commands-examples/
12/14
21.11.2014
::DownloadFreeLinuxeBooks::
CompleteLinuxCommandLineCheatSheet
TheGNU/LinuxAdvancedAdministrationGuide
Securing&OptimizingLinuxServers
LinuxPatchManagement:KeepingLinuxUpToDate
IntroductiontoLinuxAHandsonGuide
UnderstandingtheLinuxVirtualMemoryManager
LinuxBiblePackedwithUpdatesandExercises
ANewbiesGettingStartedGuidetoLinux
LinuxfromScratchCreateYourOwnLinuxOS
LinuxShellScriptingCookbook,SecondEdition
Securing&OptimizingLinux:TheHackingSolution
UserModeLinuxUnderstandingandAdministration
::FollowUs::
http://www.tecmint.com/scp-commands-examples/
13/14
21.11.2014
TecMint.com
google.com/+Tecmint
Tecmint: Linux Howtos, Tutorials & Guides
2 evre
+1
+ 9.033
::About::
TecMint.comisawebsitethatpublishespracticalandusefuloutoftheboxarticlesforaspirantlikeyouand
me.Weseektopresentexceptional,remarkabletips,tutorials,andresourcesthatthemodernwebprofessional
willappreciate.
::OurServices::
KnowMore
WeofferwiderangeofLinuxWebHostingandManagementServicesincludesLinuxhosting,
WordPresshosting,JoomlaHosting,CMShosting,WebsitemigrationandCustomsolutions,makingusaone
stopdestinationforallyourpossiblehostingneedsatfairminimumrates.
::Advertise::
SubmitOrder
TecMint.comisvisitedbytensofthousandsofLinuxusersandhasaexcellentreputationinthe
searchengineranking.MostofthetrafficcomesfromGoogleorganicsearch(80%).Spreadyourmessagesor
productstoanengagedreadersbyadvertisingwithus.
Thisworkislicensedundera(cc)BYNC|TecMintusescookies.Byusingourservices,you
complytouseofourcookies.Moreinfo:PrivacyPolicy.
20122014AllRightsReserved.
AdvertiseNow
10UsefulFreeLinuxeBooksforNewbiesandAdministrators
25HardeningSecurityTipsforLinuxServers
60CommandsofLinux:AGuidefromNewbiestoSystemAdministrator
15CommandLineToolstoMonitorLinuxPerformance
5BestPracticestoSecureandProtectSSHServer
18TarCommandExamplesinLinux
20LinuxYUM(YellowdogUpdater,Modified)Commands
25UsefulBasicCommandsofAPTGETandAPTCACHE
20FunnyCommandsofLinuxorLinuxisFuninTerminal
35PracticalExamplesofLinuxFindCommand
10LinuxDistributionsandTheirTargetedUsers
http://www.tecmint.com/scp-commands-examples/
14/14