Linux常用命令(2)

Posted by Marlin on May 27, 2026

scp

scp [-r] <source> <target>
The scp command allows you to transfer files or directories securely between a local and a remote host (or between two remote hosts).

  1. From Local to Remote (upload):
1
2
3
4
5
# transfer a dirctory
scp -r ./example_dir 192.168.0.10:/root

# transfer a single file
scp ./example_file.md 192.168.0.10:/root
  1. From Remote to Local (download): Of course, you can also transfer files from a remote host to your local machine:
1
2
3
4
5
# download a directory
scp -r 192.168.0.10:/root/example_dir /root

# download a single file
scp 192.168.0.10:/root/example_file.md /root

ssh

ssh [-L/R <local_port>:<target_host>:<target_port>] <user@ssh_server>
The ssh(Secure Shell) command is used to log in to remote server or to set up “port forwarding”. Port forwarding allows you to securely transfer data between your local machine and a remote server by tunneling traffic through the SSH connection.

  1. Log in to Remote Server
  1. Local Port Forward
1
ssh -L 8080:localhost:80 [email protected]

This command can transfer data from your local port(8080) to remote port(192.168.0.10:80).If the target host is the SSH server itself, you can use localhost as the target address.

  1. Remote Port Forward
1
ssh -R 8080:localhost:80 [email protected]

This command forwards traffic from a remote port(8080) back to local port(80) on your machine. This is useful for making a local service accessible to the remote server.