`
kimnin
  • 浏览: 11059 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

Passwordless SSH logins

阅读更多

 

Passwordless SSH logins

http://www.cs.utah.edu/~bigler/code/sshkeys.html


There are a few cases where having passwordless access to a machine is convenient or necessary. I'm always looking up a series of commands that I can just copy and paste to do it right quick. Here they are.

  1. Generate your key pair - One of the login modes of ssh is to use a SSH key pair. A key pair is made up of both a private and a public key. The private key is kept on your local machine while your public key is what you distribute to all the machines you want to log in to. There are a few flavors of keys you can generate, rsa1 (for SSH1), dsa (SSH2), or rsa (SSH2). According to my IT guy he likes DSA. You can (and should) associate a password with your key pair, so that only you can use it even if someone else manages to gain access to your account. If you have more than one key pair, using the same password for all key pairs will make them all active at the same time. You can also vary the number of bits used for the key. The more bits you use the harder it will be to crack, but I believe at a nominal performance drop. I was recommended to use 2048 bits. Very well, 2048 bit DSA key it is.
    ssh-keygen -t dsa -b 2048
    # Type in strong password
    
    If for some reason you need an rsa key, you can just replace the type with the appropiate argument, -t rsa or -t rsa1.

    NOTE: You need to make sure the permissions of the files in this directory are set to allow read/write for the user only (-rw------- or chmod 600 *). The most important files to do this for are the authorized_keys and private keys files. Sometimes logging in will silently fail if you don't have the permissions set correctly.

    
    
  2. Copy public key to remote machine - Once you made your key pair, you should copy your public key to the remote machine preferably using an encrypted method such as scp and add it to your .ssh/authorized_keys file. You can do this with a single command.
    cat ~/.ssh/id_dsa.pub | ssh user@remote.machine.com 'cat >> .ssh/authorized_keys'
    
    # If you need to make a .ssh directory on the remote machine
    cat ~/.ssh/id_dsa.pub | ssh user@remote.machine.com 'mkdir .ssh; cat >> .ssh/authorized_keys'
    
  3. SSH Agent - Now that you have a pair, you can try logging into the remote machine as you normally would. You will be prompted for your key pair password. If you left it blank when you created your keys you may simply press enter (and SHAME on you). If you press enter at this point and you had a password you will then be prompted for your remote account password. You can avoid having to do this by using ssh-agent. This will allow you to type in your password for the key pair once on a given machine and reuse it over and over again. ssh-agent stores information about your keys in the memory of that system, so if you move to another system or the machine is rebooted you will have to run ssh-agent again. ssh-agent also will output some environment variables that you can use to gain access to the keys in memory. I have a couple of aliases that help me out with this. One thing to consider is adding a time limit to how long your keys will be active in memory. If you want them to last for only a day you can add -t 86400 (those are seconds) to your ssh-agent command.
    # For tcsh
    
    # Activates the key pairs and stores some helper files.  Run this once per
    # machine you want to log from.
    
    alias agent 'rm -f "$HOME"/.ssh/`hostname`.agent ; ssh-agent -t 86400 | grep -v echo > "$HOME"/.ssh/`hostname`.agent ; source "$HOME"/.ssh/`hostname`.agent ; ssh-add'
    
    # Run this in any shell after 'agent' to "activate" the keys.
    
    alias sshagent 'if (-e "$HOME"/.ssh/`hostname`.agent) source "$HOME"/.ssh/`hostname`.agent ; endif'
    
    # For bash
    
    alias agent='rm -f "$HOME"/.ssh/`hostname`.agent ; ssh-agent -t 86400 | grep -v echo > "$HOME"/.ssh/`hostname`.agent ; source "$HOME"/.ssh/`hostname`.agent ; ssh-add'
    alias sshagent='if [ -e "$HOME"/.ssh/`hostname`.agent ]; then source "$HOME"/.ssh/`hostname`.agent ; fi'
    
    
    Now you should simply be able to run agent once on the machine, and then sshagent once per shell. You can then log into the remote machine without having to type in a password. If your ssh agent expires (you'll know, because you'll be propted for your password), then run agent again.
    
    
  4. Root access - You can also give users the ability to log into the machine as root without having to give the root password out. Just add the users public key to list of root's authorized_keys, and then the user can log into the machine using root as the user name.
    # Admin does
    cat ~user/.ssh/id_dsa.pub | ssh root@remote.machine.com 'cat >> .ssh/authorized_keys'
    
    # User does
    agent
    sshagent; ssh root@remote.machine.com
    
    # Or by typing the key pair's password
    ssh root@remote.machine.com
    
    It is recommended that once you have the ability to log in remotely as root with keys, you should disable password-based logins via ssh by making sure the following line is in /etc/ssh/sshd_config:
    PermitRootLogin   without-password
分享到:
评论

相关推荐

    logins.nasl

    logins

    bash-last-logins:显示上次登录(今天、昨天)并且仍然打开 ssh 连接

    显示上次登录(今天、昨天)并且仍然打开 ssh 连接。 它会稍微延迟登录到您的机器。 基于 IQAndreas 的工作: 。 它现在还显示今天和昨天的登录。 它使用了没有修改。 用法 获取文件 bash-last-logins 编辑您的 ....

    linux密码正确 却无法登陆

    此现象发生在本地显示器连接的情况下,远程SSH连接则可以正常进行。 #### 分析原因 出现该问题的原因可能涉及多个方面: 1. **PAM配置问题**:PAM(Pluggable Authentication Modules)是Linux系统中用于处理用户...

    Salesforce Logins by Synebo-crx插件

    语言:English 一流的解决方案,可管理您的Salesforce凭证。 完全免费。 主要功能–提高生产力:支持安全令牌。 对验证码说“再见”! 分组,快速搜索和一键式登录到新标签页,窗口甚至隐身模式。...

    Force.com LOGINS-crx插件

    语言:English 帮助您管理Salesforce登录凭据,并使您只需单击一下即可登录。 该扩展名可帮助您管理Salesforce登录凭据,并让您快速登录。 ... 该扩展程序可以为您提供帮助; ...-在所有设备上同步您的登录信息-自动将帐户...

    Force.com登录「Force.com LOGINS」-crx插件

    让你登陆Force.com,点击... ...-可让您使用新标签页登录到所选帐户 -可让您使用新窗口(单独的会话)登录到您选择的帐户 -将您的帐户分组以便于管理 ...-以XML格式导出和导入帐户信息。...希望这个对你有帮助!...支持语言:English

    Logins:在登录到我的世界服务器时控制玩家位置

    登录 ... description: Show a list of current logins aliases: [ll] permissions: 删除登录点: description: Remove a Login Point aliases: [rlp] permission: 设置场点: description: Ad

    cypress-social-logins:使用社交网络提供商的赛普拉斯身份验证流

    柏树社交登录 使用社交网络提供商的cypress认证流程 关于 该赛普拉斯库使执行诸如GitHub,Google或Facebook之类的服务的第三方登录(如oauth)成为可能。 通过将登录过程委派给puppeteer流程来执行,该流程执行登录...

    springmvc_hibernate_security_demo

    springmvc_hibernate_security项目搭建源码,包括数据库。 博文地址:http://blog.csdn.net/fengshizty/article/details/43732815

    oracle select top的方法

    SELECT * FROM FND_LOGINS ORDER BY login_id DESC ) WHERE ROWNUM ``` 2. **使用ROW_NUMBER()**: ```sql SELECT * FROM ( SELECT a.*, ROW_NUMBER() OVER (ORDER BY login_id DESC) AS rn FROM FND_LOGINS...

    bpost-aspnetcore-local-logins:http

    在提供的压缩包文件名“bpost-aspnetcore-local-logins-master”中,“master”通常表示这是项目的主分支,可能包含了完成的源代码和示例,供学习者参考和调试。 总的来说,这个主题涵盖了ASP.NET Core 2.0的本地...

    Secure Logins-crx插件

    语言:English (United States) ... ...每个Google帐户都维护了一个单独的文件,您可以访问您的Google帐户的登录信息。什么是新的?...功能列表:--------------------1....2.有一个单独的注销按钮,以在您的Google帐户注销后保持...

    安全登录「Secure Logins」-crx插件

    ...每个Google帐户都有一个单独的文件,您可以通过登录您的Google帐户访问特定的文件。 什么是新的: -------------------- ... 功能列表: -------------------- 1.使用OAuth2授权从Google帐户进行一次安全登录。...

    ACM CCS 2017论文集 PART1

    ACM CCS 2017会议论文集 The ACM Conference on Computer and Communications Security (CCS) is the flagship annual conference of the Special Interest Group on Security, Audit and Control (SIGSAC) of the ...

    sql 连续天数查询

    假设我们有一个名为`user_logins`的表,其中包含`user_id`(用户ID)和`login_date`(登录日期)两个字段,那么我们可以执行以下查询: ```sql SELECT t1.user_id, t1.login_date, t2.login_date, DATEDIFF(t2....

    TREVORspray:基于MSOLSpray的功能强大的循环SOCKS代理和Python O365喷雾器,使用Microsoft Graph API

    #trevorforget TREVORproxy和TREVORspray TREVORproxy是一个SOCKS代理,可通过SSH主机轮询请求。... 自动取消/恢复(尝试的用户/密码组合会记住在./logs/tried_logins.txt ) 仅使用vanilla --ssh通过多个IP的轮

    通用linux系统安全加固 (2).pdf

    优化SSH配置,例如禁用密码登录,只允许公钥认证,限制SSH端口,以及使用防火墙(如`iptables`)阻止不必要的SSH连接。 10. 更新和补丁管理: 定期更新系统和软件包,安装安全补丁,以修复已知的安全漏洞。 11. ...

    CentOS5中vsftp虚拟用户配置

    本文介绍了CentOS5中vsftp虚拟用户配置的实例,包括安装db4-utils软件包、创建logins_list文件、生成vsftpd_login.db文件、配置PAM认证、创建vsftpd_user_conf目录、配置vsftpd.conf文件、重启vsftpd服务等步骤。...

Global site tag (gtag.js) - Google Analytics