ssh ip change
2018-02-20 19:50
162 查看
https://www.v2ex.com/t/139986
http://blog.csdn.net/nolan__roronoa/article/details/52335223 http://blog.csdn.net/rongku/article/details/50402314
1. 163 turn on smtp service (login into email box to set up)
see pic from https://www.cnblogs.com/bass6/p/5544265.html
and
blog.csdn.net/nolan__roronoa/article/details/52335223
2. install msmtp (mailPassword, use 授权码 given by the step 1.)
sudo apt-get install msmtp
(1) 在/etc目录下创建msmtprc的配置文件/etc/msmtprc(msmtprc文件默认是没有的,要自己创建)
sudo vi msmtprc
#Accounts will inherit settings from this section
defaults
account 163
host smtp.163.com
port 25
from lin_eyun@163.com
auth login
tls off
user lin_eyun@163.com
password mailPassword
logfile /var/log/msmtp.log
# Set a default account
account default : 163
(2) 创建上述配置的日志文件
sudo touch /var/log/msmtp.log
为了让所有用户都能读写这个日志文件,我们将其权限设置为777
sudo chmod 777 /var/log/msmtp.log
(3) 创建~/.msmtprc文件
vi .msmtprc
defaults
account 163
host smtp.163.com
port 25
from lin_eyun@163.com
auth plain
user lin_eyun@163.com
password mailPassword
account default:163
logfile ~/.msmtp.log
由于password是明文,所以需要修改此文件的访问权限,以下设置是只给.msmtprc的所属用户读和写的权限,其他人没有任何权限
sudo chmod 600 .msmtprc
(4) 创建上述配置中的log文件touch ~/.msmtp.log
(5) test of sending an email:
msmtp lin_eyun@163.com
test
键Ctrl+d
3. install mutt,
sudo apt-get install mutt
'Postfix configuration'界面,键盘点击箭头->使光标移到ok,点enter
“General type of mailconfiguration”中选择第三个”mail sent by smarthost;no localmail”,然后依次配置下去,在”Ip address or host name of the outgoingsmarthost”中,填入smtp.163.com等类似的smtp服务器地址,然后,其他的就很简单了(http://blog.sina.com.cn/s/blog_9ada6acf0100yh2d.html)
配置 mutt,系统全局设置配置文件在 /etc/Muttrc,如果使用某个系统用户,可以在~/.muttc中设置,没有该文件,就自己创建。
编辑 sudo vi Muttrc
在Muttrc文件最后添加以下内容
set sendmail="/usr/bin/msmtp"
set use_from=yes
set realname="eyun"
set from=lin_eyun@163.com
set envelope_from=yes
4. 测试邮件发送
echo "test" |mutt -s "my_first_test" lin_eyun@163.com
5. cron
installed by default of ubuntu https://www.linuxidc.com/Linux/2015-08/121087.htm
6. 弄了一个守护进程,每分钟检查一下ip
4000
有没有变,如果变了就把新ip以邮件形式发到我邮箱里,实现的依赖:msmtp,mutt,cron。首先要把邮件配置好。ifconfig查看本机ip, 看本机对应的是eth0/ppp0/wlp3s0/等。
具体的实现脚本:#!/bin/bash
IPADDRESS=$(ifconfig eth0 | sed -n 's/.*inet addr:\([^ ]*\).*/\1/p')
echo "Last check at: $(date)" >> updateip.log
if [[ "${IPADDRESS}" != $(cat ~/.current_ip) ]];then
if echo "${IPADDRESS}" | mutt -s "new ip" myemail@com ;then
echo "Ip change from $(cat ~/.current_ip) to ${IPADDRESS}" >> updateip.log
echo ${IPADDRESS} > ~/.current_ip
else
echo "Failed to send the mail, try again later." >> updateip.log
fi
fi
保存在~/bin/unpdateip.sh
然后在/etc/crontab文件最后加上一行:
* * * * * <user> bash ~/bin/updateip.sh
http://blog.csdn.net/nolan__roronoa/article/details/52335223 http://blog.csdn.net/rongku/article/details/50402314
1. 163 turn on smtp service (login into email box to set up)
see pic from https://www.cnblogs.com/bass6/p/5544265.html
and
blog.csdn.net/nolan__roronoa/article/details/52335223
2. install msmtp (mailPassword, use 授权码 given by the step 1.)
sudo apt-get install msmtp
(1) 在/etc目录下创建msmtprc的配置文件/etc/msmtprc(msmtprc文件默认是没有的,要自己创建)
sudo vi msmtprc
#Accounts will inherit settings from this section
defaults
account 163
host smtp.163.com
port 25
from lin_eyun@163.com
auth login
tls off
user lin_eyun@163.com
password mailPassword
logfile /var/log/msmtp.log
# Set a default account
account default : 163
(2) 创建上述配置的日志文件
sudo touch /var/log/msmtp.log
为了让所有用户都能读写这个日志文件,我们将其权限设置为777
sudo chmod 777 /var/log/msmtp.log
(3) 创建~/.msmtprc文件
vi .msmtprc
defaults
account 163
host smtp.163.com
port 25
from lin_eyun@163.com
auth plain
user lin_eyun@163.com
password mailPassword
account default:163
logfile ~/.msmtp.log
由于password是明文,所以需要修改此文件的访问权限,以下设置是只给.msmtprc的所属用户读和写的权限,其他人没有任何权限
sudo chmod 600 .msmtprc
(4) 创建上述配置中的log文件touch ~/.msmtp.log
(5) test of sending an email:
msmtp lin_eyun@163.com
test
键Ctrl+d
3. install mutt,
sudo apt-get install mutt
'Postfix configuration'界面,键盘点击箭头->使光标移到ok,点enter
“General type of mailconfiguration”中选择第三个”mail sent by smarthost;no localmail”,然后依次配置下去,在”Ip address or host name of the outgoingsmarthost”中,填入smtp.163.com等类似的smtp服务器地址,然后,其他的就很简单了(http://blog.sina.com.cn/s/blog_9ada6acf0100yh2d.html)
配置 mutt,系统全局设置配置文件在 /etc/Muttrc,如果使用某个系统用户,可以在~/.muttc中设置,没有该文件,就自己创建。
编辑 sudo vi Muttrc
在Muttrc文件最后添加以下内容
set sendmail="/usr/bin/msmtp"
set use_from=yes
set realname="eyun"
set from=lin_eyun@163.com
set envelope_from=yes
4. 测试邮件发送
echo "test" |mutt -s "my_first_test" lin_eyun@163.com
5. cron
installed by default of ubuntu https://www.linuxidc.com/Linux/2015-08/121087.htm
6. 弄了一个守护进程,每分钟检查一下ip
4000
有没有变,如果变了就把新ip以邮件形式发到我邮箱里,实现的依赖:msmtp,mutt,cron。首先要把邮件配置好。ifconfig查看本机ip, 看本机对应的是eth0/ppp0/wlp3s0/等。
具体的实现脚本:#!/bin/bash
IPADDRESS=$(ifconfig eth0 | sed -n 's/.*inet addr:\([^ ]*\).*/\1/p')
echo "Last check at: $(date)" >> updateip.log
if [[ "${IPADDRESS}" != $(cat ~/.current_ip) ]];then
if echo "${IPADDRESS}" | mutt -s "new ip" myemail@com ;then
echo "Ip change from $(cat ~/.current_ip) to ${IPADDRESS}" >> updateip.log
echo ${IPADDRESS} > ~/.current_ip
else
echo "Failed to send the mail, try again later." >> updateip.log
fi
fi
保存在~/bin/unpdateip.sh
然后在/etc/crontab文件最后加上一行:
* * * * * <user> bash ~/bin/updateip.sh
相关文章推荐
- ssh直线IP端口转发
- ssh brute force attack IP list
- 如何设置ssh安全只允许用户从指定的IP登陆
- ssh 不能连上服务器 hosts.deny没有没限制ip 找不到什么原因
- centos+bond+bridge+docker(ssh容器)固定ip实现测试环境(二)
- hosts.deny和hosts.allow限制SSH登陆的IP
- SSH 连接linux 设定ip的方法
- zabbix应用---检查ssh登录ip 推荐
- linux ip&dns&ssh 配置
- 将ssh失败尝试达到100次以上的IP拒绝掉
- 新版raspbian系统的固定IP配置和启用root账户的ssh登录功能的方法
- SSH限制某些用户/ip登录
- FreeBSD配置ip和开启SSH
- ssh登录错误ECDSA host key for ip has changed解决方案
- linux 在使用ssh实现内网互联互通时候提示connected by ip 错误的解决方法
- centos+bond+bridge+docker(ssh容器)固定ip实现测试环境(三)
- ubuntu14.04 ssh 远程连接和静态ip的设置
- Linux 下ssh创建ip加密码隧道
- ubuntu 设置为固定ip并通过ssh 访问