每周一个编程小知识
本地终端登录远程服务器(常用)
示例:
cd ~/.ssh
ssh root@110.110.110.110 -p 22 // ssh user@remote -p port
user: 指的是你在远程服务器上的用户名,如果不指定的话,默认为当前用户。上面示例中的root就是指的用户,这个root拥有设备系统中的所有权限,可以对系统进行启动或停止等功能。
remote: 指的是远程机器的地址,可以是IP,域名,或者是别名。上面示例中的110.110.110.110为IP。
port: 指的是SSH Server 监听的端口,如果不指定的话,默认为22(ssh默认端口)。 上面的示例中 -p 22 可以去掉,如果需要其它端口,则需要-p来指定其它端口。
使用scp将本地文件或文件夹上传到远程服务器
上传本地文件:
scp /path/file user@remote:/path
// 使用示例:scp /Users/public/index.html root@110.110.110.110:/neworiental/code/project
上面的使用示例上传成功后,会将index.html文件上传到服务器的porject文件夹下面。
上传本地文件夹:
scp -r /path/file user@remote:/path
// 使用示例:scp -r /Users/public root@110.110.110.110:/neworiental/code/project
上面的使用示例上传成功后,会将public文件夹上传到服务器的porject文件夹下面。
使用scp将服务器上的文件或文件夹下载到本地
下载文件到本地:
scp user@remote:/path/file /path
// 使用示例:scp root@110.110.110.110:/neworiental/dist/index.html /Users/Desktop
上面的使用示例中,服务器上的index.html文件将会被下载到本地的Desktop(桌面)上。注意服务器上的文件路径和本地文件路径之间有个空格。
下载文件夹到本地:
scp -r user@remote:/path /path
// 使用示例:scp -r root@110.110.110.110:/neworiental/dist /Users/Desktop
上面的使用示例中,服务器上的dist文件夹将会被下载到本地的Desktop(桌面)上。注意服务器上的文件路径和本地文件路径之间有个空格。