how to ssh logon remote host without password

本文详细介绍如何在两台机器之间配置SSH免密登录。通过生成公钥和私钥,并将公钥添加到目标机器的authorized_keys文件中,实现从左机器到右机器的安全、便捷登录。文章还提供了权限设置建议及常见问题排查方法。
ou want to connect from machine "left" to machine "right".

Log into left:
mkdir ~/.ssh
cd ~/.ssh
ssh-keygen -b 1024 -t rsa1 -C "you@yourdomain.com" -N ""
ssh-keygen -b 1024 -t rsa -C "you@yourdomain.com" -N ""
ssh-keygen -b 1024 -t dsa -C "you@yourdomain.com" -N ""

This creates six files in your ~/.ssh directory:
identity
identity.pub
id_rsa
id_rsa.pub
id_dsa
id_dsa.pub

Log into right:
mkdir ~/.ssh
cd ~/.ssh

On right, create a file called "authorized_keys" (in the ~/.ssh directory). Paste the contents of the three .pub files created earlier into this file (you will have to work out for yourself the best way to do this).

Now test it out. On left:
ssh username@right

It should let you in without a password. If it does not, the first thing to check is your file permissions. The ~/.ssh directories on both sides should not be writable by anyone but the owner. The .pub files should be readable by everyone, but the other key files should only be readable by their owner. The permissions should be set correctly by ssh-keygen, but you never know. There are a lot of things that can go wrong here; troubleshooting is complicated and well beyond the scope of these instructions.
### 解决方案 当遇到 `ORA-01017: invalid username/password` 错误时,通常是因为数据库认证协议不匹配或者用户名/密码配置错误。以下是可能的原因以及解决方案: #### 1. 数据库版本兼容性问题 如果客户端和服务器端的 Oracle 版本不同,则可能会触发此错误。Oracle 官方文档指出,在某些情况下,旧版客户端尝试连接到较新的数据库实例可能导致认证失败[^1]。 解决方法: - 确认客户端和服务器端的 Oracle 版本是否一致。 - 如果无法升级客户端,可以考虑调整服务器端参数以支持较低的安全协议(仅限必要情况)。例如,设置 `sqlnet.allowed_logon_version_server` 和 `sqlnet.allowed_logon_version_client` 参数为合适的值。 ```bash # 修改 sqlnet.ora 文件 sqlnet.allowed_logon_version_server=8 sqlnet.allowed_logon_version_client=8 ``` #### 2. 密码文件未启用 如果没有正确配置远程登录密码文件 (`remote_login_passwordfile`),则可能导致认证失败。默认情况下,该参数值为 `NONE`,表示不允许通过密码文件验证用户身份[^2]。 解决方法: - 启用密码文件功能并重新生成密码文件。 ```sql -- 设置 spfile 中的参数 ALTER SYSTEM SET remote_login_passwordfile='EXCLUSIVE' SCOPE=SPFILE; -- 关闭并重启数据库实例 SHUTDOWN IMMEDIATE; STARTUP; ``` - 使用 `$ORACLE_HOME/bin/orapwd` 工具创建或更新密码文件。 ```bash orapwd file=$ORACLE_HOME/dbs/orapw<sid> password=<new_password> force=y ``` #### 3. 用户名或密码输入错误 确认所提供的用户名和密码是否正确无误。注意区分大小写,并确保没有多余的空格字符。 测试命令: ```sql CONNECT <username>/<password>@<database_service_name>; ``` #### 4. 认证协议冲突 (ORA-28040) 如果启用了更高的安全级别而客户端未能满足相应要求,则会引发此类问题。具体表现为 `No Matching Authentication Protocol` 的提示信息。 处理方式: - 调整 SQLNET 配置文件中的允许最低登录版本选项; - 或者降级客户端至与服务端相适应的状态。 --- ### 总结 综合以上分析可知,针对 `ORA-01017` 及其关联异常现象的有效应对策略包括但不限于校验账户凭证准确性、激活全局共享存储机制下的口令档案管理特性以及优化网络层面上的身份鉴别交互流程等方面的工作内容。 ```python def test_connection(username, password, service_name): try: connection_string = f"{username}/{password}@{service_name}" result = execute_sql(f"CONNECT {connection_string}") return True if "Connected." in result else False except Exception as e: print(e) return False ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值