返回首页   进站必读

1.29 ssh/scp


1.29.1 ssh

大多数人以前没有接触过Linux系统,都是从Windows系统过来的,Windows下的一些实用功能例如共享文件,这样的功能在Linux系统也是可以实现的,而且更便捷。
先在要登陆的机器上安装ssh-server服务:

$ sudo apt-get install openssh-server
查看该机器的IP:
$ ifconfig
假设我们查询到这台机器的IP为192.168.0.247,并且知道这台机器的用户名和密码,在自己的机器上进行如下操作:
$ ssh xwp@192.168.0.247
The authenticity of host '192.168.0.247
(192.168.0.247)' can't be established. 
RSA key fingerprint is 6a:0d:44:dc:41:5e:8b:f7:a2:9f:9c:2d:47:92:4b:c8. Are you sure you want to continue connecting (yes/no)?yes
xwp@192.168.0.247's password: xwp@xwp-desktop:~$
这样我们就用自己的机器连接上了另一台机器,我们可以用命令行对这台机器进行操作。

1.29.2 scp

下面我们介绍如何复制另一台机器上的文件,比如我们要复制192.168.0.247:/home/xwp/mind 目录到本地,如下操作:

$ scp -r xwp@192.168.0.247:/home/xwp/mind ./

The authenticity of host '192.168.0.247 (192.168.0.247)' can't be
established.
RSA key fingerprint is 6a:0d:44:dc:41:5e:8b:f7:a2:9f:9c:2d:47:92:4b:c8.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts
(/home/ymqqqqdx/.ssh/known\_hosts).
xwp@192.168.0.247's password:
linux.mm 100% 2070 2.0KB/s 00:00
gfh.mm 100% 1792 1.8KB/s 00:00
$ ls . .. mind
下面介绍一个如何将本地的文件复制到远端,这个一定要掌握,因为在以后的学习中,提交代码采用这种方式。例如:本地的目录为yourname,要提交这个目录,教师机的IP地址为192.168.0.247,代码提交到教师机的/home/xwp/code/下:
$ scp -r yourname xwp@192.168.0.247:/home/xwp/code/
 
the authenticity of host '192.168.0.247 (192.168.0.247)' can't be established.  
RSA key fingerprint is 6a:0d:44:dc:41:5e:8b:f7:a2:9f:9c:2d:47:92:4b:c8.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts
(/home/ymqqqqdx/.ssh/knownhosts).
xwp@192.168.0.247's password:
main.c 100% 34KB 33.9KB/s 00:00
add.c 100% 2417 2.4KB/s 00:00