6

Linux基础:ssh与scp - 江水为竭

 1 year ago
source link: https://www.cnblogs.com/Az1r/p/17021056.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Linux基础:ssh与scp - 江水为竭 - 博客园

  • 登陆服务器

  • ssh user@hostname

    • user: 用户名
    • hostname :IP地址或域名
  • 第一次登陆会提示

    • The authenticity of host '123.57.47.211 (123.57.47.211)' can't be established.
      ECDSA key fingerprint is SHA256:iy237yysfCe013/l+kpDGfEG9xxHxm0dnxnAbJTPpG8.
      Are you sure you want to continue connecting (yes/no/[fingerprint])?

  • 输入yes ,回车即可。这样服务器的信息会记录在~/.ssh/known_hosts中。

  • 退出登陆:CTRL + D,或者手动输入 exit

  • 为方便登陆服务器,给服务器取别名。

  • 创建文件夹:~$ mkdir .ssh

  • 创建文件vim config

    • highlighter- crmsh
      Host myserver1
          HostName IP地址或域名
          User 用户名
      
      Host myserver2
          HostName IP地址或域名
          User 用户名
      
  • 则可使用别名myserver1myserver2

  • 输入命令ssh-keygen,回车跳过询问。
  • 这样, ~/.ssh 中会有文件
    • id_rsa : 私钥
    • id_rsa.pub : 公钥
  • 如果想要免密登录某个服务器,就要将公钥传给它。
    • 将公钥中的文段复制,进入服务器中。
    • 粘贴到~/.ssh/authorized_keys。(若没有,则创建)
  • 也可以这条命令一键添加:ssh-copy-id myserver
  • 命令格式ssh user@hostname command

    • ssh user@hostname ls -a ,将服务器家目录下所有文件夹打印出。

    • shell
      a=1
      ssh myserver  "echo $a"
      ssh myserver  'echo $a'
    • 双引号是在本地服务器进行转义,所以传过去的命令不是echo $a,而是echo 1单引号传过去的是echo $a

  • 功能:本地与服务器之间传文件,服务器与服务器之间传送需要权限完整,可以让本地终端成为媒介。
  • source路径下的文件复制到destination
    • scp source destination
  • 复制多个文件
    • scp source1 source2 destination
  • 复制文件夹
    • 将本地家目录中的tmp文件夹复制到myserver服务器中的~/homework/目录下。
    • scp -r ~/tmp myserver:homework/
  • 指定端口号
    • scp -P 22 source1 source2 destination
  • 传输作业
    • 在作业文件夹的目录下,如~/CSAPP/homework1
    • 命令scp -P 22 * user@hostname:~/homework1

__EOF__


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK