折腾:
【已解决】Mac中iTerm2通过SSH连接远程服务器
期间,此处去搞清楚终端 命令行 中如何用ssh去连接远程服务器。
发现直接登录后,也还可以:
➜ .ssh ssh [email protected] The authenticity of host 'x.x.x.116 (x.x.x.116)' can't be established. ECDSA key fingerprint is SHA256:euNIYbfr0+QBvBpCuT+gui9eKdKePaH9OiB/OoVfe30. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'x.x.x.116' (ECDSA) to the list of known hosts. Last login: Fri Feb 28 22:53:32 2020 from y.y.y.217 [root@xxx ~]# pwd /root [root@xxx ~]# ll 总用量 4 drwxr-xr-x 2 root root 4096 2月 28 22:05 tdengine [root@xxx ~]# cd tdengine/ [root@xxx tdengine]# ll 总用量 0 [root@xxx tdengine]# ls -lh 总用量 0
总体看来,此处的iTerm2中用ssh,感觉还是可以的。
去试试,把ssh登录的密码换成rsa秘钥文件
另外,以后有用可以试试,之前用过一个pass的东西,可以把文件中的密码,传递给要输入的地方,作为密码。去找找
先去试试ssh的秘钥登录
ssh login via rsa key
Use Public Key Authentication with SSH | Linode
How to Use SSH Public Key Authentication – ServerPilot
ssh -i ~/.ssh/custom_key_name [email protected]
Set up SSH public-key authentication to connect to a remote system
ssh -i ~/.ssh/old_keys/host2_key [email protected]
Log in with an SSH private key on Linux and macOS
ssh -i deployment_key.txt [email protected]
试试
➜ ~ ssh --help ssh: illegal option -- - usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] destination [command]
发现-i是-i identity_file,是对的。
➜ ~ ssh -i ~/.ssh/id_rsa-NeteaseCloud [email protected] Last login: Sat Feb 29 10:04:21 2020 from y.y.y.217 [root@xxx ~]# uname -a Linux xxx.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux [root@xxx ~]# lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.0.1406 (Core) Release: 7.0.1406 Codename: Core
是可以的,很是方便啊。
再去找之前的传入密码的
/Users/crifan/dev/dev_root/gitbook/gitbook_src_root/common/gitbook_makefile.mk
sshpass -f $(DEPLOY_SERVER_PASSWORD_FILE) rsync -avzh --progress --stats --delete --force $(RELEASE_PATH) $(DEPLOY_SERVER_USER)@$(DEPLOY_SERVER_IP):$(DEPLOY_SERVER_PATH)
是这个sshpass
不过先要去搞清楚:
【已解决】Mac中iTerm2中如何退出ssh
sshpass login ssh
sshpass: Login To SSH Server / Provide SSH Password Using A Shell Script – nixCraft
$ sshpass -p 't@uyM59bQ' ssh [email protected] $ sshpass -p 't@uyM59bQ' ssh -o StrictHostKeyChecking=no [email protected] sshpass -f fileNameHere ssh user@server
去试试-f的
➜ ~ sshpass -f ~/.ssh/neteaseCloudPassword.txt ssh [email protected] Last login: Sat Feb 29 10:27:00 2020 from y.y.y.217 [root@xxx ~]#
也是可以的。
【总结】
用ssh连接服务器的方式:
方式1.手动输入密码
ssh username@server_ip
然后手动输入密码
注:
首次登录会提示:
ECDSA key fingerprint is SHA256:xxx30. Are you sure you want to continue connecting (yes/no)?
输入:yes
即可继续
方式2:利用sshpass自动(免去)输入密码
sshpass -f /path/to/your/password_file ssh username@server_ip
方式3:通过秘钥文件登录(而不用密码了)
ssh -i your_key_file username@server_ip
转载请注明:在路上 » 【已解决】终端命令行中用ssh登录远程服务器