Work on another machine: ssh and scp
Log in to another machine with ssh, run commands there, come back with exit, then copy files both ways with scp. Practise on a pretend server.
Servers rarely have a screen and keyboard of their own. You reach them from your own computer with ssh (secure shell), which gives you a prompt on the other machine. As in the last lesson, web is a pretend server inside this page; nothing leaves your browser.
Logging in
ssh webThe first time you connect to a machine, ssh shows its fingerprint and asks whether to trust it. Here the practice shell answers yes for you; on a real system, check it first. Then you log in with a password or, better, a key (that's in the Advanced level).
Once you're in, the prompt changes to learner@web. Every command now runs on web, with web's files:
hostnamelsexitexit (or Ctrl+D) brings you back to your laptop. Watch the prompt: knowing which machine you're on is half the skill.
To run just one command there and come straight back, put it after the name: ssh web uptime.
Copying files: scp
scp copies over ssh, and works like cp. The side with a machine's name and a colon is on that machine:
| Command | Copies |
|---|---|
scp notes.txt web: | your notes.txt to your home folder on web |
scp notes.txt web:/tmp/ | to a folder on web |
scp web:/etc/hostname . | a file from web to here |
scp -r photos web: | a whole folder |
Run scp on your laptop, not after logging in to web. Forget the colon, and scp copies to a local file called web.
Your turn
Log in to web, read README.txt in your home folder there, and come back with exit. Then copy report.txt from your laptop to your home folder on web, and copy web’s home page, /var/www/html/index.html, to your home folder on the laptop.
Your task
Log in to web, read README.txt in your home folder there, and come back with exit. Then copy report.txt from your laptop to your home folder on web, and copy web’s home page, /var/www/html/index.html, to your home folder on the laptop.
- Log in to web and read its README.txt (not done yet)
- Come back to your laptop (not done yet)
- report.txt is on web (not done yet)
- index.html from web is on your laptop (not done yet)
The checklist ticks itself off as you work in the terminal: any way that gets the result counts.
Hints come one at a time, then one way to do it. Try each before the next.
What this lesson uses, in one place.
ssh- Log in to another machine More on ssh
exit- End a script, or log out
scp- Copy files to or from another machine More on scp
hostname- Show the machine’s name or address
Every everyday command on one page: the Linux commands cheat sheet.