使用ssh 连接linux 并传送文件

1、 在windows下使用ssh连接linux

①、连接

输入 ssh 用户名@IP 例如:ssh root@192.168.0.232

[C:\~]$ ssh root@192.168.0.232

Connecting to 192.168.0.232:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

root@okmx8mm:~# ls -al
total 332728
drwxr-xr-x 3 root root      4096 Jun 21 09:20 .
drwxr-xr-x 4 root root      4096 Mar 29  2022 ..
-rw------- 1 root root       554 Jun 21 10:11 .bash_history
-rw-r--r-- 1 root root        51 Mar 29  2022 .profile
drwx------ 2 root root      4096 Jun 21 09:15 .ssh
-rw-r--r-- 1 root root       963 Jun 21 09:21 result.log
-rwxrwxrwx 1 root root       711 Jun 21 09:20 tem.sh
-rw-r--r-- 1 root root 340672512 Jun 20 10:39 test.bin
-rwxrwxrwx 1 root root       726 Jun 20 10:02 test.sh
-rw-r--r-- 1 root root      3689 Jun 21 09:21 vmstat.log
root@okmx8mm:~# 

可以看到,已经正常链接了。

②、传送文件

要传送文件,不能在已经连接的终端上执行,首先要退出ssh链接。
拷贝linux下的/home/root/tem.sh 到e:\ 
[C:\~]$ scp root@192.168.0.232:/home/root/tem.sh e:\

Connecting to 192.168.0.232:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Start scp session to download.
tem.sh	711 字节
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(192.168.0.232:22) at 16:42:41.
Type `help' to learn how to use Xshell prompt.
[C:\~]$ dir e:\
 驱动器 E 中的卷是 tools
 卷的序列号是 0008-319D

 e:\ 的目录

2021/11/24 周三  14:31    <DIR>          1012vmware
2022/01/14 周五  14:21    <DIR>          1028
2022/01/14 周五  13:07    <DIR>          335xd
2021/11/30 周二  09:35    <DIR>          6ull-s2
2022/04/12 周二  11:51    <DIR>          999、tool
2021/11/30 周二  15:15    <DIR>          share
2022/04/19 周二  16:42               711 tem.sh
2022/01/14 周五  17:28    <DIR>          以前的资料
2022/04/18 周一  11:25    <DIR>          本机必备工具
               1 个文件            711 字节
               8 个目录 82,128,781,312 可用字节

可以看到 tem.sh 已经拷贝到e:\ 下面了。
拷贝e:\tem.sh 到linux下/home/root/tem1.sh

C:\~]$ scp e:\tem.sh root@192.168.0.232:/home/root/tem1.sh 

Connecting to 192.168.0.232:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Start scp session to upload.
tem.sh	711 字节
Sent all of files.
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(192.168.0.232:22) at 16:45:17.
Type `help' to learn how to use Xshell prompt.
[C:\~]$ ssh root@192.168.0.232

Connecting to 192.168.0.232:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

root@okmx8mm:~# pwd
/home/root
root@okmx8mm:~# ls -al
total 332732
drwxr-xr-x 3 root root      4096 Jun 21 10:18 .
drwxr-xr-x 4 root root      4096 Mar 29  2022 ..
-rw------- 1 root root       566 Jun 21 10:15 .bash_history
-rw-r--r-- 1 root root        51 Mar 29  2022 .profile
drwx------ 2 root root      4096 Jun 21 09:15 .ssh
-rw-r--r-- 1 root root       963 Jun 21 09:21 result.log
-rwxrwxrwx 1 root root       711 Jun 21 09:20 tem.sh
-rw-r--r-- 1 root root       711 Jun 21 10:18 tem1.sh
-rw-r--r-- 1 root root 340672512 Jun 20 10:39 test.bin
-rwxrwxrwx 1 root root       726 Jun 20 10:02 test.sh
-rw-r--r-- 1 root root      3689 Jun 21 09:21 vmstat.log
root@okmx8mm:~# 

可以看到已经拷贝到/home/root/,并且名称为tem1.sh

2、 在linux下使用ssh连接linux

相对于windows下,linux下使用要方便一点,因为两边都是linux系统。

①、连接

forlinx@ubuntu:~$ ssh root@192.168.0.232
The authenticity of host '192.168.0.232 (192.168.0.232)' can't be established.
ECDSA key fingerprint is SHA256:0jqQj0TgVF6Q+imwCHDfwZ4GfsJdM+u0G20Dc9Kwkn4.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.0.232' (ECDSA) to the list of known hosts.
root@192.168.0.232's password: 
Welcome to NXP LSDK 2004 main (GNU/Linux 5.4.3 aarch64)

 * Support:        https://www.nxp.com/lsdk
 * Documentation:  https://lsdk.github.io/document
 * Licensing:      https://lsdk.github.io/eula
Last login: Sat Apr  9 07:00:36 2022 from 192.168.0.200
root@forlinx:~# 
root@forlinx:~# 
root@forlinx:~# ls
bj.sh                    led.sh   r.sh        tc.sh       testusb.sh
downnet.sh               log      result.txt  test.log    testusb1.sh
getmax.sh                main     stress.sh   testmem.sh  testusb2.sh

②、传送文件

下载文件:
下载文件
scp username@servername:/path/filename /var/www/local_dir(本地目录)

forlinx@ubuntu:~$ scp root@192.168.0.232:/root/bj.sh /
root@192.168.0.232's password: 
/bj.sh: Permission denied
forlinx@ubuntu:~$ sudo scp root@192.168.0.232:/root/bj.sh /
[sudo] password for forlinx: 
The authenticity of host '192.168.0.232 (192.168.0.232)' can't be established.
ECDSA key fingerprint is SHA256:0jqQj0TgVF6Q+imwCHDfwZ4GfsJdM+u0G20Dc9Kwkn4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.232' (ECDSA) to the list of known hosts.
root@192.168.0.232's password: 
bj.sh                                         100%  215   121.8KB/s   00:00    
forlinx@ubuntu:~$ 
forlinx@ubuntu:~$ 
forlinx@ubuntu:~$ ls /
bin    dev         initrd.img.old  libx32      opt   sbin      sys  vmlinuz
bj.sh  etc         lib             lost+found  proc  snap      tmp  vmlinuz.old
boot   home        lib32           media       root  srv       usr
cdrom  initrd.img  lib64           mnt         run   swapfile  var
forlinx@ubuntu:~$ 
上传文件 
scp /path/filename username@servername:/path   

forlinx@ubuntu:~$ sudo scp /bj.sh root@192.168.0.232:/root/1/
root@192.168.0.232's password: 
bj.sh                                         100%  215   149.1KB/s   00:00    
forlinx@ubuntu:~$ 

创作不易,欢迎点赞、关注。

–好记性不如烂笔头。

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

six2me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值