最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】终端命令行中用ssh登录远程服务器

工作和技术 crifan 1072浏览 0评论

折腾:

【已解决】Mac中iTerm2通过SSH连接远程服务器

期间,此处去搞清楚终端 命令行 中如何用ssh去连接远程服务器。

发现直接登录后,也还可以:

➜  .ssh ssh root@x.x.x.116
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@lin-16core3 ~]# pwd
/root
[root@lin-16core3 ~]# ll
总用量 4
drwxr-xr-x 2 root root 4096 2月  28 22:05 tdengine
[root@lin-16core3 ~]# cd tdengine/
[root@lin-16core3 tdengine]# ll
总用量 0
[root@lin-16core3 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 SYSUSER@x.x.x.x

Set up SSH public-key authentication to connect to a remote system

ssh -i ~/.ssh/old_keys/host2_key username@host2.somewhere.edu

Log in with an SSH private key on Linux and macOS

ssh -i deployment_key.txt demo@192.237.248.66

试试

➜  ~ 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 root@x.x.x.116
Last login: Sat Feb 29 10:04:21 2020 from y.y.y.217
[root@lin-16core3 ~]# uname -a
Linux lin-16core3.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@lin-16core3 ~]# 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 username@server.example.com
$ sshpass -p 't@uyM59bQ' ssh -o StrictHostKeyChecking=no username@server.example.com
sshpass -f fileNameHere ssh user@server

去试试-f的

➜  ~ sshpass -f ~/.ssh/neteaseCloudPassword.txt ssh root@x.x.x.116
Last login: Sat Feb 29 10:27:00 2020 from y.y.y.217
[root@lin-16core3 ~]#

也是可以的。

【总结】

用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登录远程服务器

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
70 queries in 0.107 seconds, using 18.91MB memory