7

linux 远程ssh管理

 3 years ago
source link: https://www.80shihua.com/archives/2702
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管理

ssh全称是secure shell,意思是安全的shell链接,通过对发送的信息进行秘钥加密,可以实现交互的安全。

本地创建秘钥

ssh-keygen -t rsa -C 80shihua -f ~/.ssh/id_rsa -N mima -P passphrase

  • -t 表示加密方式type的意思

  • -f 表示存储路径file的意思

  • -C表示备注信息comment的意思

  • -N表示新的密码,new passphrase

  • -P表示密码,就是passphrase的意思

秘钥生成后会默认保存到用户家目录下的.ssh/id_rsa,此外还会生成一个公钥,id_rsa.pub

拷贝秘钥到主机

ssh-copy-id -i ~/.ssh/id_rsa.pub    [email protected]

上述命令会将公钥拷贝到远程主机上面的~/.ssh/authorized_keys 文件中,之后在远程主机的时候就不需要再输入密码了。

通过hostname访问

如果想更简单地访问,比如想要下面的访问方式

ssh dev

我们就可以通过配置sssconfig来实现 找到本地的.ssh目录,创建config文件 然后输入下面的配置

Host dev
    HostName 115.28.72.250
    User root
    IdentityFIle ~/.ssh/id_rsa

现在我们就可以使用简单地命令访问我们的远程主机了。

当一个命令变得复杂的时候,我们总是会通过配置文件,或者重新映射来简化命令,这也是shell的精髓。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK