> eval `ssh-agent` (yes, these are backticks)
> ssh-add ~/.ssh/id_rsa
================================================================================
In quite a few situations its preferred to have ssh keys dedicated for a service or a specific role. Eg. a key to use for home / fun stuff and another one to use for Work things, and another one for Version Control access etc. Creating the keys is simple, just use
ssh-keygen -t rsa -f ~/.ssh/id_rsa.work -C "Key for Word stuff"
Use different file names for each key. Lets assume that there are 2 keys, ~/.ssh/id_rsa.work and ~/.ssh/id_rsa.misc . The simple way of making sure each of the keys works all the time is to now create config file for ssh:
touch ~/.ssh/config
chmod 600 ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.work" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.misc" >> ~/.ssh/config
This would make sure that both the keys are always used whenever ssh makes a connection. However, ssh config lets you get down to a much finer level of control on keys and other per-connection setups. And I recommend, if you are able to, to use a key selection based on the Hostname. My ~/.ssh/config looks like this :
Host *.home.lan IdentityFile ~/.ssh/id_dsa.home User kbsingh Host *.vpn IdentityFile ~/.ssh/id_rsa.work User karanbir Port 44787 Host *.d0.karan.org IdentityFile ~/.ssh/id_rsa.d0 User admin Port 21871
Ofcourse, if I am connecting to a remote host that does not match any of these selections, ssh will default back to checking for and using the 'usual' key, ~/.ssh/id_dsa or ~/.ssh/id_rsa
===================================================================================
SSH has a per-user configuration file called ‘~/.ssh/config’ that it can use to select your private keys based on the remote user name and remote host by using wildcards. Let’s check out my ‘config’ file:
IdentityFile ~/.ssh/ids/%h/%r/id_rsa IdentityFile ~/.ssh/ids/%h/%r/id_dsa IdentityFile ~/.ssh/ids/%h/id_rsa IdentityFile ~/.ssh/ids/%h/id_dsa IdentityFile ~/.ssh/id_rsa IdentityFile ~/.ssh/id_dsa
The percent-h and percent-r take the host and the remote user from your SSH user and hostname arguments. Consider this example command:
$ ssh remote_user@remote_hostname.example.com
From the example command, the SSH client would use the wildcards to seek the correct key to use:
~/.ssh/ids/remote_hostname.example.com/remote_user/
This means that if you had two private keys that you used to access two different servers, you would arrange them as follows. The first one is arranged as follows:
$ ls -l ~/.ssh/ids/remote.example.com/remote_user/ total 16 -rw------- 1 kelvin staff 668 Mar 24 20:09 id_dsa -rw-r--r-- 1 kelvin staff 610 Mar 24 20:09 id_dsa.pub $ ssh remote_user@remote.example.com [remote_user@remote ~]$ |
Our second example uses a simple hostname. If a remote user is not required, you can just use the hostname:
$ ls -l ~/.ssh/ids/webby.example.org/ total 16 -rw------- 1 kelvin staff 668 Mar 24 20:09 id_rsa -rw-r--r-- 1 kelvin staff 610 Mar 24 20:09 id_rsa.pub $ ssh webby.example.org [webby ~]$ |
For sure, these are totally contrived examples, but you can watch the cascade yourself by adding the verbosity flag(s) to your SSH client session (this one is my client’s WebFaction account):
相关推荐
更新SSH密钥 :warning: 此板条箱已弃用且未维护 :warning: update-ssh-keys不再维护; 推荐的替代方法是 。 update-ssh-keys工具authorized_keys.d通过提供程序和库从合并键authorized_keys.d/*成authorized_keys...
以下角色经过了综合测试,可以很好地工作-至少对于用户: (此) Protipp:Deploy the manage_users role *before* deploying the ssh keys.If the user does not exist it is hard to add a ssh key for him!...
sshkeys - 获取ssh服务器的所有ssh公钥
The client's private key is loaded via SSHFTPClient's setAuthentication method before calling connect, supplying the full path of the private key file, the SSH username and the passphrase of the ...
开源项目-Eun-sshkeys.zip,sshkeys - Get all ssh public keys of a ssh server
#=> /Users/wilmoore/.ssh/authorized_keyskeys('git');#=> /Users/git/.ssh/authorized_keys视窗 keys();#=> C:\Users\wilmoore\.ssh\authorized_keyskeys('git');#=> C:\Users\git\.ssh\authorized_keysLinux keys...
ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ...
ssh-copy-id命令可以把本地主机的公钥复制到远程主机的authorized_keys文件上,ssh-copy-id命令也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh/authorized_keys设置合适的权限。 语法格式:ssh-copy-id ...
该文档适用于小白使用,讲述了在遇到问题时,如何添加SSH key。
https://code.csdn.net/x13015851932/jll-vimide-sh项目的ssh私钥
SSH密钥方式登录Linux,SSH密钥方式登录Linux
ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ssh 框架 ...
ssh高级ssh高级ssh高级ssh高级ssh高级ssh高级ssh高级ssh高级
$ touch ~ /.ssh/authorized_keys && touch ~ /.ssh/known_hosts 将公共密钥添加到授权密钥文件中 $ cat ~ /.ssh/id_rsa.pub >> ~ /.ssh/authorized_keys 激活ssh代理 $ ssh-add ~ /.ssh/id_rsa 配置对文件的以下...
ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh框架项目源码ssh...
ssh-信任主机方式,建立crt连接 实现从主机A直接 SSH 到主机B,C,无需密码 在LINUX配置主机信任时,对对端机(被免口令登录机器)的目录权限和文件权限相关说明:对端机的authorized_keys改为只有当前用户读取权限...
SSH Mastery_ OpenSSH, PuTTY, Tunnels and Keys. 12-Tilted Windmill Press (2018).epub
ssh,ssh集成,ssh,ssh集成 ssh集成
Ansible-ansible-ssh-keys.zip,负责管理类debian系统sssh密钥中的ssh密钥,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。