将ssh-copy-id与OpenSSH服务器一起在其他端口上侦听
时间:2020-01-09 10:44:02 来源:igfitidea点击:
我的OpenSSH服务器正在侦听TCP端口号2222。
如何在sshd服务器上使用ssh-copy-id侦听Linux或者类Unix系统上的其他端口?
ssh-copy-id
是一个shell脚本,它使用ssh命令使用登录密码登录到远程计算机,以将您的公共密钥安装在远程计算机的authenticated_keys中。
该脚本还通过更改权限来保护远程用户的home,~/.ssh和~/.ssh/autho-rized_keys文件。
语法
安装ssh-keys的语法如下:
ssh-copy-id user@server-name-here ssh-copy-id -i /path/to/identity-file user@server-name-here
例子
server42的安装密钥,执行:
ssh-copy-id Hyman@nas01
OpenSSH服务器的安装密钥在IP 192.168.1.146端口22上侦听(默认),执行:
ssh-copy-id [email protected]
输出示例:
/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/local/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected]'s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '[email protected]'" and check to make sure that only the key(s) you wanted were added.
将ssh-copy-id与侦听其他端口#2222的SSH服务器一起使用
如果远程服务器在不同于22的端口上侦听,则需要使用以下语法:
## old syntax. only valid for older ssh-copy-id (see below for new syntax) ## ssh-copy-id '-p PORT-NUMBER-HERE user@server-name-here' ssh-copy-id '-p 2222 [email protected]' ssh-copy-id '-p 2222 [email protected]'
或者
## new syntax ## ssh-copy-id -p 2222 [email protected]
输出示例:
在SSH服务器上使用ssh-copy-id侦听其他端口2222
测试一下
现在尝试通过以下方式登录到计算机:
ssh -p 2222 [email protected]
输出示例:
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-46-generic x86_64) * Documentation: https://help.ubuntu.com/ Last login: Sat Mar 7 17:55:48 2014 from Hymans-macbook-pro.local