【Linux】Linux——ssh命令を一歩ずつ学ぶ(176)

9620 ワード

00.カタログ
記事の目次
  • 00.ディレクトリ
  • 01.コマンド概要
  • .コマンドフォーマット
  • 03.常用オプション
  • 04.参考例
  • 05.付録
  • 01.コマンドの概要
    sshコマンドはopensshセットのクライアント接続ツールであり、ssh暗号化プロトコルを付与して安全なリモートログインサーバを実現し、サーバのリモート管理を実現することができます.
    02.コマンド形式
      :ssh [  ] [  ]
    
    03.一般的なオプション
    -1	    ssh    1
    -2	    ssh    2
    -4	    IPv4  
    -6	    IPv6  
    -A	            
    -a	            
    -b<IP  >	                 IP  
    -C	        
    -F<    >	  ssh       ,        “/etc/ssh/ssh_config”
    -f	    ssh  
    -g	               
    -i<    >	      (     )
    -l<   >	               
    -N	       
    -o<  >	      
    -p<  >	           
    -q	    ,               
    -X	  X11    
    -x	  X11    
    -y	    X11    
    
    04.参考例
    4.1リモートサーバに登録する
    [deng@localhost ~]$ ssh 172.16.0.76
    The authenticity of host '172.16.0.76 (172.16.0.76)' can't be established. ECDSA key fingerprint is SHA256:YheY5RH3PZ27UMYxdPwhraYfS4bCK/p3+xwdWL0O9WQ. ECDSA key fingerprint is MD5:27:a1:b7:c7:df:7d:91:04:40:bd:e9:79:bb:98:8f:e4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '172.16.0.76' (ECDSA) to the list of known hosts. [email protected]'s password: 
    Last login: Thu Aug 22 22:06:22 2019 from 172.16.0.51
    [deng@localhost ~]$ 
    
    4.2ユーザーを指定してリモートサーバに登録する
    [deng@localhost ~]$ ssh -l deng 172.16.0.76
    [email protected]'s password: 
    Last login: Thu Aug 22 22:06:33 2019 from 172.16.0.76
    [deng@localhost ~]$ 
    
    4.3リモートサーバのパーティションリストを表示する
    [deng@localhost ~]$ ssh -l root 172.16.0.76 /sbin/fdisk -l
    [email protected]'s password: 
    
       /dev/sda:107.4 GB, 107374182400   ,209715200    
    Units =    of 1 * 512 = 512 bytes
        (  /  ):512    / 512   
    I/O   (  /  ):512    / 512   
          :dos
         :0x000cc727
    
          Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      411647      204800   83  Linux
    /dev/sda2          411648     8800255     4194304   82  Linux swap / Solaris
    /dev/sda3         8800256   209715199   100457472   83  Linux
    [deng@localhost ~]$ 
    
    4.4 sshプロトコルバージョンを強制的に使用する2
    [deng@localhost ~]$ ssh -2 -l root 172.16.0.76
    [email protected]'s password: 
    Last login: Thu Aug 22 21:42:57 2019
    [root@localhost ~]# 
    
    4.5認証代理接続転送機能をオープンする
    [root@localhost ~]# ssh -A -l root 172.16.0.76
    The authenticity of host '172.16.0.76 (172.16.0.76)' can't be established. ECDSA key fingerprint is SHA256:YheY5RH3PZ27UMYxdPwhraYfS4bCK/p3+xwdWL0O9WQ. ECDSA key fingerprint is MD5:27:a1:b7:c7:df:7d:91:04:40:bd:e9:79:bb:98:8f:e4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '172.16.0.76' (ECDSA) to the list of known hosts. [email protected]'s password: 
    Last login: Thu Aug 22 22:10:56 2019 from 172.16.0.76
    [root@localhost ~]# 
    
    4.6認証代理接続転送機能をオフにする
    [root@localhost ~]# ssh -a -l root 172.16.0.76 
    [email protected]'s password: 
    Last login: Thu Aug 22 22:11:31 2019 from 172.16.0.76
    [root@localhost ~]# 
    
    4.7ユーザ登録を指定する(二)
    [root@localhost ~]# ssh [email protected]
    [email protected]'s password: 
    Last login: Thu Aug 22 22:12:26 2019 from 172.16.0.76
    [root@localhost ~]# 
    
    4.8ポートを指定してリモートサーバに登録する
    [root@localhost ~]# ssh -p 22 [email protected] 
    [email protected]'s password: 
    Last login: Thu Aug 22 22:13:31 2019 from 172.16.0.76
    [root@localhost ~]# 
    
    4.9プロキシで登録する
    [root@localhost ~]# ssh -D 7576 [email protected]
    [email protected]'s password: 
    Last failed login: Thu Aug 22 22:15:00 CST 2019 from 172.16.0.76 on ssh:notty
    There was 1 failed login attempt since the last successful login.
    Last login: Thu Aug 22 22:14:03 2019 from 172.16.0.76
    [root@localhost ~]# 
    
    4.10リモートコマンドを実行する
    [root@localhost ~]# ssh [email protected] date
    [email protected]'s password: 
    2019  08  22      22:15:56 CST
    [root@localhost ~]# 
    
    4.11リモートホストでグラフィックインターフェースのプログラムを実行する
    [root@localhost ~]# ssh -X [email protected]
    [email protected]'s password: 
    
    4.12バインディングソースアドレス
    [root@localhost ~]# ssh -b 172.16.0.76 [email protected]
    [email protected]'s password: 
    Last login: Thu Aug 22 22:20:55 2019 from 172.16.0.76
    [deng@localhost ~]$ 
    
    4.13すべてのデータに対して圧縮を要求する
    [deng@localhost ~]$ ssh -C [email protected]
    [email protected]'s password: 
    Last login: Thu Aug 22 22:22:00 2019 from 172.16.0.76
    [deng@localhost ~]$ ls
    
    4.14デバッグモードを開く
    [deng@localhost ~]$ ssh -v [email protected]
    OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 58: Applying options for *
    debug1: Connecting to 172.16.0.76 [172.16.0.76] port 22.
    debug1: Connection established.
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/deng/.ssh/id_rsa type -1
    
    4.15サイレントモードでは、すべての警告と診断情報の出力が禁止されています.
    [deng@localhost ~]$ ssh -q [email protected]
    [email protected]'s password: 
    Last failed login: Thu Aug 22 22:23:52 CST 2019 from 172.16.0.76 on ssh:notty
    There were 2 failed login attempts since the last successful login.
    Last login: Thu Aug 22 22:22:34 2019 from 172.16.0.76
    [deng@localhost ~]$ 
    
    05.付録
    参考:【Linux】一歩ずつLinuxシリーズの教程まとめ