每天一條Linux命令(24) ssh (遠端安全登入)
在Linux系統中,命令 ssh 是openssh套件中的客戶端連線工具,可以使用ssh加密協議實現安全的遠端登入伺服器,實現對伺服器的遠端管理,Windows中的替代工具為Xshell、putty、SecureCRT等。
語法:
ssh [引數選項] [user@IP] [command]
[注] command 是可選項
引數說明:
-
-p 指定ssh登入埠號,預設為22 埠
-
-t 強制分配偽終端,可以在遠端機器上執行任何全螢幕(screen-based)程式,所以非常有用,例如選單服務。即使沒有本地終端,多個-t選項也會強制分配終端。這個選項在進行寫遠端批量管理Shell指令碼時非常有有用
-
-v 除錯模式
案例:
遠端登入伺服器
[C:\~]$ ssh root@192.168.116.100
Connecting to 192.168.116.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
指定使用者及埠進行遠端登入
[C:\~]$ ssh -p 22 bear@192.168.116.100
Connecting to 192.168.116.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
遠端執行命令
[root@master test03]#
[root@master test03]# ssh 120.24.165.81 "ls" # 在另一個伺服器上執行ls命令
root@120.24.165.81's password: # 輸入另一個伺服器登入密碼
install.sh # 執行結果
[root@master test03]#
-v 開始除錯模式 (這裡以除錯遠端登入慢為例,其實並不慢,這裡只是演示一下過程)
[root@master test03]# ssh -v 120.25.168.64
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 120.24.165.81 [120.24.165.81] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 120.25.168.64:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:+QXNO8vg3Dmngg0Ek90haDDp+PNvI/koo5gLPwSyhgU
debug1: Host '120.24.165.81' is known and matches the ECDSA host key.
# 略略略略略略略略略略
debug1: Next authentication method: password
root@120.24.165.81's password: # 這裡提示需要輸入密碼
debug1: Authentication succeeded (password).
Authenticated to 120.24.165.81 ([120.25.168.64]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Sun Sep 20 17:37:28 2020 from 115.194.183.70
Welcome to Alibaba Cloud Elastic Compute Service !
[root@iZwz9c8miiew8bjh7tpbveZ ~]#
上述除錯過程,如果卡在哪一步說明問題就出在哪裡(這裡除錯登入時其實是正常的)
相關文章
- Linux 遠端 ssh 登入Linux
- Linux更改SSH遠端登入埠教程Linux
- SSH遠端登入原理
- ssh遠端登入協議協議
- Linux Debian11伺服器安裝SSH,建立新使用者並允許SSH遠端登入,及SSH安全登入配置!Linux伺服器
- SSH 遠端登入「記住密碼」密碼
- linux SSH服務允許root使用者遠端登入Linux
- 使用SSH命令列遠端登入執行在CloudFoundry上的應用命令列Cloud
- Ubuntu開啟ssh服務遠端登入Ubuntu
- Shuttle - Mac 下的遠端SSH登入工具Mac
- 從一起Linux雲主機無法遠端ssh登入故障說起Linux
- ssh遠端連結(簡易連線linux命令)Linux
- SSH免密登入與SCP遠端複製
- Ubuntu中允許root遠端ssh登入的方法Ubuntu
- 華為eNSP基礎入門-配置SSH遠端登入
- 如何遠端登入Linux系統?Linux
- Linux學習--遠端登入Linux系統Linux
- Linux SSH遠端訪問Linux
- SSH以及ROS遠端登入設定保姆級教程ROS
- 一個ssh無法遠端登入的問題跟蹤解決
- VS Code / Pycharm配置SSH遠端開發(免密登入)PyCharm
- Mac SSH 免密登入 連線遠端伺服器Mac伺服器
- Go實現ssh執行遠端命令及遠端終端Go
- 【Linux】apt軟體管理和遠端登入LinuxAPT
- linux遠端免密登入伺服器Linux伺服器
- Linux(CentOS 7)VMWare下配置遠端登入LinuxCentOS
- Ubuntu遠端登入相關命令簡介(1)Ubuntu
- Linux(9)-遠端登入Linux系統以及apt管理LinuxAPT
- 如何通過 SSH 在遠端 Linux 系統上執行命令Linux
- ssh安全的自動登入
- Linux下 SSH遠端管理服務Linux
- Linux伺服器---ssh登入Linux伺服器
- windows ssh遠端登入阿里雲遇到permissions are too open的錯誤Windows阿里
- Solaris 11 設定root使用者允許SSH遠端登入
- rocky one 遠端登入
- redis - 遠端登入指令Redis
- Go語言:crypto/ssh執行遠端命令Go
- ssh遠端連線linux伺服器Linux伺服器