ssh-config是使用openssh
的ssh config
的功能,需要编辑~/.ssh/config
这个文件。打开终端,然后输入vi ~/.ssh/config
Host demo(这个随你取名)
HostName xx.x.x.x(你的服务器外网ip)
User root(用户名)
Port 22(端口)
然后你就可以通过输入 ssh demo
登录你的服务器,当然这时候还需要输入密码。
如果你需要免密码登录的话,则需要配置秘钥,这里使用的是ssh-copy-id
这个功能。
首先需要在本地生成秘钥,打开终端,输入如下命令:
ssh-keygen
然后将秘钥复制到远程的服务器
ssh-copy-id -i 用户名@x.x.x.x
这时候需要输入密码,然后登录远程服务器,你就会在远程服务器的~/.ssh/文件夹下发现一个authorized_keys
文件,里面就是我们刚刚复制的秘钥了。
至此,你以后登录远程服务器就只需要在终端输入ssh demo(你~/.ssh/config中设置的名字)就可以直接登录远程服务器了。
alfred
如果你不知道什么是Alfred的话,可以跳过这一步,而且正版软件要45欧元,当然网上的破解版本也很多。这个软件可以通过快捷的命令完成设定的事。
alfred_ssh_setting
打开alfred后,依次打开feature-Terminal,然后再Application中选择Custom,然后在下面的框中输入下面的命令。
on alfred_script(q)
if application "iTerm2" is running or application "iTerm" is running then
run script "
on run {q}
tell application \":Applications:iTerm.app\"
activate
try
select first window
set onlywindow to true
on error
create window with default profile
select first window
set onlywindow to true
end try
tell the first window
if onlywindow is false then
create tab with default profile
end if
tell current session to write text q
end tell
end tell
end run
" with parameters {q}
else
run script "
on run {q}
tell application \":Applications:iTerm.app\"
activate
try
select first window
on error
create window with default profile
select first window
end try
tell the first window
tell current session to write text q
end tell
end tell
end run
" with parameters {q}
end if
end alfred_script
参考:https://hacpai.com/article/1567998289912
插件下载地址:
https://github.com/deanishe/alfred-ssh
下载完成后,双击打开Secure-SHell-0.8.0.alfredworkflow
并安装就完成了。
iterm2_ssh
按照上图,在iTem2的Preference中的Profiles中设置Schemes handled中选择ssh。
看下图,只要输入ssh name
,其中name为你之前设置的名字,这一连串的简单操作是不是非常简单便捷。
macOS使用iterm2登录ssh