ssh配置免密登录
生成公钥和私钥
Windows
在桌面,键盘按
win键+r键,输入cmd,回车,打开cmd终端输入:1
ssh-keygen -t rsa
一路回车
Linux
打开终端,输入:
1
ssh-keygen -t rsa
一路回车
复制刚刚生成的公钥
Windows
在桌面,键盘按
win键+r键,输入cmd,回车,打开cmd终端输入:1
notepad %HOMEPATH%/.ssh/id_rsa.pub
复制这一行
Linux
打开终端,输入:
1
cat ~/.ssh/id_rsa.pub
复制输出的结果
[!注意]
这一行很长!一定要复制完。格式以
ssh-rsa xxxxxxxx开头,以你的用户名@你的系统名结尾,如:
1 ssh-rsa AAAA......xxxx= satan\satan@SatanGT
将本地的公钥复制到服务器上
通用方法
登录linux后,先检查有没有
~/.ssh/authorized_keys文件,如果没有,输入:1
2
3
4mkdir ~/.ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys将刚才复制的公钥粘贴到authorized_keys里。
或输入:
1
echo ssh-rsa AAAA......xxxx= user@host(上面复制的公钥) >> ~/.ssh/authorized_keys
Linux快捷指令
打开终端,输入:1
2
3
4# 将user@remote-server换成你的服务器,可以带端口等选项
ssh-copy-id user@remote-server
# 或
ssh-copy-id -i ~/.ssh/work_key.pub -p 2222 user@remote-server
至此,后续的ssh可以免密登录。
常用的指令
- tab补全忽略大小写
1
echo 'set completion-ignore-case on' >> ~/.inputrc
.bashrc1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24case $- in
*i*) ;;
*) return;;
esac
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
if [ -e $HOME/.bash_functions ]; then
source $HOME/.bash_functions
fi.bash_functions1
2
3
4
5
6
7
8
9
10function cd() {
DIR="$*";
# if no DIR given, go home
if [ $# -lt 1 ]; then
DIR=$HOME;
fi;
builtin cd "${DIR}" && \
# use your preferred ls command
ls -F --color=auto
}.bash_aliases1
2
3
4
5
6
7
8
9
10alias gh='history|grep'
alias cpv='rsync -ah --info=progress2'
alias ..='cd ..'
alias ...='cd ../..'
alias untar='tar -zxvf '
alias pg='ps -aux|grep '
woc_he() {
curl -s "https://ipinfo.io/${1:-}"
echo
}检测本机ip
1
2curl ipinfo.io
curl ifconfig.me检测他人ip
1
curl ipinfo.io/[ip]